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 3 1. getPath : replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → NO_COVERAGE
2. getPath : replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → KILLED
3. getPath : replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → KILLED
		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 3 1. getName : replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → SURVIVED
2. getName : replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → NO_COVERAGE
3. getName : replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → KILLED
		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 5 1. extractName : changed conditional boundary → SURVIVED
2. extractName : changed conditional boundary → NO_COVERAGE
3. extractName : Replaced integer addition with subtraction → NO_COVERAGE
4. extractName : negated conditional → SURVIVED
5. extractName : negated conditional → NO_COVERAGE
		name = colonIdx >= 0 ? name.substring(colonIdx + 1) : name;
86 2 1. extractName : replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::extractName → SURVIVED
2. 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 3 1. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → NO_COVERAGE
2. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → SURVIVED
3. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → KILLED
		return new HashCodeBuilder().append(name, path).hashCode();
92
	}
93
94
	@Override
95
	public boolean equals(Object obj) {
96 4 1. equals : replaced boolean return with false for fr/sii/ogham/core/resource/LookupResource::equals → NO_COVERAGE
2. equals : replaced boolean return with true for fr/sii/ogham/core/resource/LookupResource::equals → NO_COVERAGE
3. equals : replaced boolean return with false for fr/sii/ogham/core/resource/LookupResource::equals → KILLED
4. equals : replaced boolean return with true for fr/sii/ogham/core/resource/LookupResource::equals → KILLED
		return new EqualsBuilder(this, obj).appendFields("name", "path").isEqual();
97
	}
98
}

Mutations

68

1.1
Location : getPath
Killed by : oghamall.it.email.EmailSMTPDefaultsTest.attachmentLookup(oghamall.it.email.EmailSMTPDefaultsTest)
replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → KILLED

2.2
Location : getPath
Killed by : none
replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → NO_COVERAGE

3.3
Location : getPath
Killed by : oghamcore.ut.core.EqualsTest.lookupSource(oghamcore.ut.core.EqualsTest)
replaced return value with null for fr/sii/ogham/core/resource/LookupResource::getPath → KILLED

78

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

2.2
Location : getName
Killed by : none
replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → NO_COVERAGE

3.3
Location : getName
Killed by : oghamcore.ut.core.EqualsTest.lookupSource(oghamcore.ut.core.EqualsTest)
replaced return value with "" for fr/sii/ogham/core/resource/LookupResource::getName → KILLED

85

1.1
Location : extractName
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : extractName
Killed by : none
changed conditional boundary → NO_COVERAGE

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

4.4
Location : extractName
Killed by : none
negated conditional → SURVIVED

5.5
Location : extractName
Killed by : none
negated conditional → NO_COVERAGE

86

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

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

91

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

2.2
Location : hashCode
Killed by : oghamcore.ut.core.EqualsTest.lookupSource(oghamcore.ut.core.EqualsTest)
replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → KILLED

3.3
Location : hashCode
Killed by : none
replaced int return with 0 for fr/sii/ogham/core/resource/LookupResource::hashCode → SURVIVED

96

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

2.2
Location : equals
Killed by : oghamcore.ut.core.EqualsTest.lookupSource(oghamcore.ut.core.EqualsTest)
replaced boolean return with false for fr/sii/ogham/core/resource/LookupResource::equals → KILLED

3.3
Location : equals
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/resource/LookupResource::equals → NO_COVERAGE

4.4
Location : equals
Killed by : oghamcore.ut.core.EqualsTest.lookupSource(oghamcore.ut.core.EqualsTest)
replaced boolean return with true for fr/sii/ogham/core/resource/LookupResource::equals → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM