AbstractPrefixedLookupPathResolver.java

1
package fr.sii.ogham.core.resource.resolver;
2
3
import static java.util.Arrays.asList;
4
5
import java.util.ArrayList;
6
import java.util.List;
7
8
import fr.sii.ogham.core.exception.resource.ResourceResolutionException;
9
import fr.sii.ogham.core.resource.Resource;
10
import fr.sii.ogham.core.resource.path.ResolvedPath;
11
import fr.sii.ogham.core.resource.path.ResolvedResourcePath;
12
import fr.sii.ogham.core.resource.path.ResourcePath;
13
14
/**
15
 * ResourceResolver using a list of supported lookups to compute a simple
16
 * {@link ResolvedResourcePath} where resolved path is simply the given path
17
 * without the lookup. Eg : classpath resource "classpath:/package/file" to
18
 * resolved path is "package/file".
19
 * 
20
 * @author Cyril Dejonghe
21
 *
22
 */
23
public abstract class AbstractPrefixedLookupPathResolver implements ResourceResolver {
24
	private List<String> lookups;
25
26
	protected AbstractPrefixedLookupPathResolver(List<String> lookups) {
27
		super();
28
		this.lookups = lookups;
29
	}
30
31
	protected AbstractPrefixedLookupPathResolver(String... lookups) {
32
		this(new ArrayList<>(asList(lookups)));
33
	}
34
35
	@Override
36
	public boolean supports(ResourcePath path) {
37 2 1. supports : negated conditional → RUN_ERROR
2. supports : replaced boolean return with true for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::supports → RUN_ERROR
		return getLookup(path) != null;
38
	}
39
40
	public String getLookup(ResourcePath path) {
41
		for (String lookup : lookups) {
42 1 1. getLookup : negated conditional → RUN_ERROR
			if (path.getOriginalPath().startsWith(lookup)) {
43 1 1. getLookup : replaced return value with "" for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::getLookup → RUN_ERROR
				return lookup;
44
			}
45
		}
46 1 1. getLookup : replaced return value with "" for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::getLookup → RUN_ERROR
		return null;
47
	}
48
49
	/**
50
	 * Find the resource using the resource path (or its name).
51
	 * 
52
	 * @param resourcePath
53
	 *            the path of the resource
54
	 * @return the found resource
55
	 * @throws ResourceResolutionException
56
	 *             when the resource couldn't be found
57
	 */
58
	protected abstract Resource getResource(ResolvedPath resourcePath) throws ResourceResolutionException;
59
60
	@Override
61
	public Resource getResource(ResourcePath path) throws ResourceResolutionException {
62 1 1. getResource : replaced return value with null for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::getResource → RUN_ERROR
		return getResource(resolve(path));
63
	}
64
65
	@Override
66
	public ResolvedPath resolve(ResourcePath path) {
67 1 1. resolve : negated conditional → RUN_ERROR
		if (path instanceof ResolvedPath) {
68 1 1. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::resolve → RUN_ERROR
			return (ResolvedPath) path;
69
		}
70
		ResolvedPath result = null;
71
		String lookup = getLookup(path);
72 1 1. resolve : negated conditional → RUN_ERROR
		if (lookup != null) {
73
			result = new ResolvedResourcePath(path, lookup, path.getOriginalPath().substring(lookup.length()));
74
		}
75 1 1. resolve : replaced return value with null for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::resolve → RUN_ERROR
		return result;
76
	}
77
}

Mutations

37

1.1
Location : supports
Killed by :
negated conditional → RUN_ERROR

2.2
Location : supports
Killed by :
replaced boolean return with true for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::supports → RUN_ERROR

42

1.1
Location : getLookup
Killed by :
negated conditional → RUN_ERROR

43

1.1
Location : getLookup
Killed by :
replaced return value with "" for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::getLookup → RUN_ERROR

46

1.1
Location : getLookup
Killed by :
replaced return value with "" for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::getLookup → RUN_ERROR

62

1.1
Location : getResource
Killed by :
replaced return value with null for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::getResource → RUN_ERROR

67

1.1
Location : resolve
Killed by :
negated conditional → RUN_ERROR

68

1.1
Location : resolve
Killed by :
replaced return value with null for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::resolve → RUN_ERROR

72

1.1
Location : resolve
Killed by :
negated conditional → RUN_ERROR

75

1.1
Location : resolve
Killed by :
replaced return value with null for fr/sii/ogham/core/resource/resolver/AbstractPrefixedLookupPathResolver::resolve → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1