LookupResource.java

1
package fr.sii.ogham.core.resource;
2
3
import java.io.File;
4
import java.io.IOException;
5
import java.io.InputStream;
6
7
import fr.sii.ogham.core.resource.path.ResourcePath;
8
import fr.sii.ogham.core.util.EqualsBuilder;
9
import fr.sii.ogham.core.util.HashCodeBuilder;
10
11
/**
12
 * <p>
13
 * Resource that is able to handle string path prefixed by a lookup string. The
14
 * lookup is case sensitive and must end with a ':'. It must not contain another
15
 * ':' character.
16
 * </p>
17
 * <p>
18
 * For example, a path could be "classpath:/email/hello.pdf". The lookup is
19
 * "classpath:".
20
 * </p>
21
 * <p>
22
 * The lookup can also be empty. The template path could then be
23
 * "/email/hello.pdf".
24
 * </p>
25
 * 
26
 * @author Aurélien Baudet
27
 *
28
 */
29
public class LookupResource implements NamedResource {
30
	/**
31
	 * The path that may contain a lookup
32
	 */
33
	private ResourcePath path;
34
35
	/**
36
	 * The name of the attachment
37
	 */
38
	private String name;
39
40
	/**
41
	 * Initialize the resource with the provided path to the resource content.
42
	 * The path may contain a lookup. The name is used for naming the resource.
43
	 * 
44
	 * @param path
45
	 *            the path to the resource (may contain a lookup)
46
	 * @param name
47
	 *            the name to display for the resource
48
	 */
49
	public LookupResource(ResourcePath path, String name) {
50
		super();
51
		this.path = path;
52
		this.name = name;
53
	}
54
55
	/**
56
	 * Initialize the resource with the provided path to the resource content.
57
	 * The path may contain a lookup. The name of the resource is automatically
58
	 * extracted from the provided path.
59
	 * 
60
	 * @param path
61
	 *            the path to the resource (may contain a lookup)
62
	 */
63
	public LookupResource(ResourcePath path) {
64
		this(path, extractName(path));
65
	}
66
67
	public ResourcePath getPath() {
68 1 1. getPath : replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → RUN_ERROR
		return path;
69
	}
70
71
	@Override
72
	public InputStream getInputStream() throws IOException {
73
		throw new UnsupportedOperationException("It doesn't directly point to the resource. It needs the underlying real resource associated to the lookup to be able to provide the stream");
74
	}
75
76
	@Override
77
	public String getName() {
78 1 1. getName : replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → RUN_ERROR
		return name;
79
	}
80
81
	private static String extractName(ResourcePath resolvedPath) {
82
		String path = resolvedPath.getOriginalPath();
83
		String name = new File(path).getName();
84
		int colonIdx = name.indexOf(':');
85 3 1. extractName : Replaced integer addition with subtraction → NO_COVERAGE
2. extractName : negated conditional → NO_COVERAGE
3. extractName : changed conditional boundary → NO_COVERAGE
		name = colonIdx >= 0 ? name.substring(colonIdx + 1) : name;
86 1 1. extractName : replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::extractName → NO_COVERAGE
		return name;
87
	}
88
89
	@Override
90
	public int hashCode() {
91 1 1. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → RUN_ERROR
		return new HashCodeBuilder().append(name, path).hashCode();
92
	}
93
94
	@Override
95
	public boolean equals(Object obj) {
96 2 1. equals : replaced boolean return with false for fr/sii/ogham/core/resource/LookupResource::equals → RUN_ERROR
2. equals : replaced boolean return with true for fr/sii/ogham/core/resource/LookupResource::equals → RUN_ERROR
		return new EqualsBuilder(this, obj).appendFields("name", "path").isEqual();
97
	}
98
}

Mutations

68

1.1
Location : getPath
Killed by :
replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → RUN_ERROR

78

1.1
Location : getName
Killed by :
replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → RUN_ERROR

85

1.1
Location : extractName
Killed by :
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : extractName
Killed by :
negated conditional → NO_COVERAGE

3.3
Location : extractName
Killed by :
changed conditional boundary → NO_COVERAGE

86

1.1
Location : extractName
Killed by :
replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::extractName → NO_COVERAGE

91

1.1
Location : hashCode
Killed by :
replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → RUN_ERROR

96

1.1
Location : equals
Killed by :
replaced boolean return with false for fr/sii/ogham/core/resource/LookupResource::equals → RUN_ERROR

2.2
Location : equals
Killed by :
replaced boolean return with true for fr/sii/ogham/core/resource/LookupResource::equals → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1