forked from junit-team/junit5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
892 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
junit-platform-commons/src/main/java/org/junit/platform/commons/support/Resource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.support; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.function.Predicate; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* Represents a resource on the classpath. | ||
* | ||
* @see ReflectionSupport#findAllResourcesInClasspathRoot(URI, Predicate, Predicate) | ||
* @see ReflectionSupport#findAllResourcesInPackage(String, Predicate, Predicate) | ||
* @see ReflectionSupport#findAllResourcesInModule(String, Predicate, Predicate) | ||
* @see ReflectionSupport#streamAllResourcesInClasspathRoot(URI, Predicate, Predicate) | ||
* @see ReflectionSupport#streamAllResourcesInPackage(String, Predicate, Predicate) | ||
* @see ReflectionSupport#streamAllResourcesInModule(String, Predicate, Predicate) | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "1.11") | ||
public interface Resource { | ||
|
||
/** | ||
* Get the resource name. | ||
* <p> | ||
* The resource name is a {@code /}-separated path. The path is relative to | ||
* the classpath root in which the resource is located. | ||
* | ||
* @return the resource name; never {@code null} | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Get URI to a resource. | ||
* | ||
* @return the uri of the resource; never {@code null} | ||
*/ | ||
URI getUri(); | ||
|
||
/** | ||
* Returns an input stream for reading this resource. | ||
* | ||
* @return an input stream for this resource; never {@code null} | ||
* @throws IOException if an I/O exception occurs | ||
*/ | ||
default InputStream getInputStream() throws IOException { | ||
return getUri().toURL().openStream(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.util; | ||
|
||
import java.net.URI; | ||
import java.util.Objects; | ||
|
||
import org.junit.platform.commons.support.Resource; | ||
|
||
class ClasspathResource implements Resource { | ||
private final String name; | ||
private final URI uri; | ||
|
||
ClasspathResource(String name, URI uri) { | ||
this.name = Preconditions.notNull(name, "name must not be null"); | ||
this.uri = Preconditions.notNull(uri, "uri must not be null"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public URI getUri() { | ||
return uri; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
ClasspathResource that = (ClasspathResource) o; | ||
return name.equals(that.name) && uri.equals(that.uri); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, uri); | ||
} | ||
} |
Oops, something went wrong.