RelativeResolutionAssertions.java

1
package fr.sii.ogham.testing.assertion.internal;
2
3
import static org.hamcrest.MatcherAssert.assertThat;
4
5
import java.util.List;
6
import java.util.Set;
7
8
import org.apache.commons.lang3.reflect.FieldUtils;
9
import org.hamcrest.Matcher;
10
11
import fr.sii.ogham.core.resource.resolver.RelativeResolver;
12
import fr.sii.ogham.testing.util.HasParent;
13
14
/**
15
 * Make assertions on resource resolution.
16
 * 
17
 * <pre>
18
 * {@code
19
 * .pathPrefix(is("/custom/"))
20
 * .pathSuffix(is(".html"))
21
 * }
22
 * </pre>
23
 * 
24
 * @author Aurélien Baudet
25
 *
26
 * @param <P>
27
 *            the parent type
28
 */
29
public class RelativeResolutionAssertions<P> extends HasParent<P> {
30
	private final String name;
31
	private final Set<RelativeResolver> relativeResolvers;
32
33
	public RelativeResolutionAssertions(P parent, String name, Set<RelativeResolver> relativeResolvers) {
34
		super(parent);
35
		this.name = name;
36
		this.relativeResolvers = relativeResolvers;
37
	}
38
39
	/**
40
	 * Ensures that path prefix is correctly configured.
41
	 * 
42
	 * @param matcher
43
	 *            the matcher to ensure that path prefix is correct
44
	 * @return this instance for fluent chaining
45
	 */
46
	public RelativeResolutionAssertions<P> pathPrefix(Matcher<? super String> matcher) {
47
		for (RelativeResolver resolver : relativeResolvers) {
48 2 1. pathPrefix : removed call to org/hamcrest/MatcherAssert::assertThat → SURVIVED
2. pathPrefix : removed call to org/hamcrest/MatcherAssert::assertThat → NO_COVERAGE
			assertThat(name + " prefix", getPrefix(resolver), matcher);
49
		}
50 2 1. pathPrefix : replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathPrefix → NO_COVERAGE
2. pathPrefix : replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathPrefix → KILLED
		return this;
51
	}
52
53
	/**
54
	 * Ensures that path suffix is correctly configured.
55
	 * 
56
	 * @param matcher
57
	 *            the matcher to ensure that path suffix is correct
58
	 * @return this instance for fluent chaining
59
	 */
60
	public RelativeResolutionAssertions<P> pathSuffix(Matcher<? super String> matcher) {
61
		for (RelativeResolver resolver : relativeResolvers) {
62 2 1. pathSuffix : removed call to org/hamcrest/MatcherAssert::assertThat → NO_COVERAGE
2. pathSuffix : removed call to org/hamcrest/MatcherAssert::assertThat → SURVIVED
			assertThat(name + " suffix", getSuffix(resolver), matcher);
63
		}
64 2 1. pathSuffix : replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathSuffix → NO_COVERAGE
2. pathSuffix : replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathSuffix → KILLED
		return this;
65
	}
66
67
	/**
68
	 * Ensures that lookup prefixes ("classpath:", "file:", ...) are correctly
69
	 * configured.
70
	 * 
71
	 * @param matcher
72
	 *            the matcher to ensure that lookup prefixes are correct
73
	 * @return this instance for fluent chaining
74
	 */
75
	public RelativeResolutionAssertions<P> lookup(Matcher<? super List<String>> matcher) {
76
		for (RelativeResolver resolver : relativeResolvers) {
77 2 1. lookup : removed call to org/hamcrest/MatcherAssert::assertThat → NO_COVERAGE
2. lookup : removed call to org/hamcrest/MatcherAssert::assertThat → SURVIVED
			assertThat(name + " lookups", getLookups(resolver), matcher);
78
		}
79 2 1. lookup : replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::lookup → NO_COVERAGE
2. lookup : replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::lookup → KILLED
		return this;
80
	}
81
82
	private static String getPrefix(RelativeResolver resolver) {
83
		try {
84 2 1. getPrefix : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getPrefix → NO_COVERAGE
2. getPrefix : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getPrefix → KILLED
			return (String) FieldUtils.readField(resolver, "parentPath", true);
85
		} catch (IllegalAccessException e) {
86
			throw new IllegalStateException("Failed to get 'parentPath' field of RelativeResolver", e);
87
		}
88
	}
89
90
	private static String getSuffix(RelativeResolver resolver) {
91
		try {
92 2 1. getSuffix : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getSuffix → NO_COVERAGE
2. getSuffix : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getSuffix → SURVIVED
			return (String) FieldUtils.readField(resolver, "extension", true);
93
		} catch (IllegalAccessException e) {
94
			throw new IllegalStateException("Failed to get 'extension' field of RelativeResolver", e);
95
		}
96
	}
97
98
	@SuppressWarnings("unchecked")
99
	private static List<String> getLookups(RelativeResolver resolver) {
100
		try {
101 2 1. getLookups : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getLookups → NO_COVERAGE
2. getLookups : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getLookups → KILLED
			return (List<String>) FieldUtils.readField(resolver.getActualResourceResolver(), "lookups", true);
102
		} catch (IllegalAccessException e) {
103
			throw new IllegalStateException("Failed to get 'lookups' field of " + resolver.getClass().getSimpleName(), e);
104
		}
105
	}
106
107
}

Mutations

48

1.1
Location : pathPrefix
Killed by : none
removed call to org/hamcrest/MatcherAssert::assertThat → SURVIVED

2.2
Location : pathPrefix
Killed by : none
removed call to org/hamcrest/MatcherAssert::assertThat → NO_COVERAGE

50

1.1
Location : pathPrefix
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathPrefix → KILLED

2.2
Location : pathPrefix
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathPrefix → NO_COVERAGE

62

1.1
Location : pathSuffix
Killed by : none
removed call to org/hamcrest/MatcherAssert::assertThat → NO_COVERAGE

2.2
Location : pathSuffix
Killed by : none
removed call to org/hamcrest/MatcherAssert::assertThat → SURVIVED

64

1.1
Location : pathSuffix
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathSuffix → KILLED

2.2
Location : pathSuffix
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::pathSuffix → NO_COVERAGE

77

1.1
Location : lookup
Killed by : none
removed call to org/hamcrest/MatcherAssert::assertThat → NO_COVERAGE

2.2
Location : lookup
Killed by : none
removed call to org/hamcrest/MatcherAssert::assertThat → SURVIVED

79

1.1
Location : lookup
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::lookup → KILLED

2.2
Location : lookup
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::lookup → NO_COVERAGE

84

1.1
Location : getPrefix
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getPrefix → KILLED

2.2
Location : getPrefix
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getPrefix → NO_COVERAGE

92

1.1
Location : getSuffix
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getSuffix → NO_COVERAGE

2.2
Location : getSuffix
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getSuffix → SURVIVED

101

1.1
Location : getLookups
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getLookups → NO_COVERAGE

2.2
Location : getLookups
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/RelativeResolutionAssertions::getLookups → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM