ResourceResolverAssertions.java

1
package fr.sii.ogham.testing.assertion.internal;
2
3
import java.util.HashSet;
4
import java.util.List;
5
import java.util.Set;
6
7
import org.apache.commons.lang3.reflect.FieldUtils;
8
9
import fr.sii.ogham.core.resource.resolver.ClassPathResolver;
10
import fr.sii.ogham.core.resource.resolver.FileResolver;
11
import fr.sii.ogham.core.resource.resolver.FirstSupportingResourceResolver;
12
import fr.sii.ogham.core.resource.resolver.RelativeResolver;
13
import fr.sii.ogham.core.resource.resolver.ResourceResolver;
14
import fr.sii.ogham.testing.util.HasParent;
15
16
/**
17
 * Make assertions on resource resolution.
18
 * 
19
 * 
20
 * <pre>
21
 * {@code
22
 *   classpath()
23
 *     .pathPrefix(is("prefix/")
24
 * }
25
 * </pre>
26
 * 
27
 * @param <P>
28
 *            the parent type
29
 */
30
public class ResourceResolverAssertions<P> extends HasParent<P> {
31
	private final Set<ResourceResolver> resolvers;
32
33
	public ResourceResolverAssertions(P parent, Set<ResourceResolver> resourceResolvers) {
34
		super(parent);
35
		this.resolvers = resourceResolvers;
36
	}
37
38
	/**
39
	 * Make assertions on classpath resolution.
40
	 * 
41
	 * <pre>
42
	 * {@code
43
	 * .pathPrefix(is("/custom/"))
44
	 * .pathSuffix(is(".html"))
45
	 * }
46
	 * </pre>
47
	 * 
48
	 * @return the builder for fluent chaining
49
	 */
50
	public RelativeResolutionAssertions<ResourceResolverAssertions<P>> classpath() {
51 2 1. classpath : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::classpath → NO_COVERAGE
2. classpath : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::classpath → KILLED
		return new RelativeResolutionAssertions<>(this, "classpath", getRelativeResolversFor(ClassPathResolver.class));
52
	}
53
54
	/**
55
	 * Make assertions on file resolution.
56
	 * 
57
	 * <pre>
58
	 * {@code
59
	 * .pathPrefix(is("/custom/"))
60
	 * .pathSuffix(is(".html"))
61
	 * }
62
	 * </pre>
63
	 * 
64
	 * @return the builder for fluent chaining
65
	 */
66
	public RelativeResolutionAssertions<ResourceResolverAssertions<P>> file() {
67 2 1. file : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::file → NO_COVERAGE
2. file : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::file → KILLED
		return new RelativeResolutionAssertions<>(this, "file", getRelativeResolversFor(FileResolver.class));
68
	}
69
70
	private <T> Set<RelativeResolver> getRelativeResolversFor(Class<T> resolverClass) {
71
		Set<RelativeResolver> found = new HashSet<>();
72
		for (ResourceResolver resolver : resolvers) {
73
			Set<RelativeResolver> relativeResolvers = findResolvers(resolver, RelativeResolver.class);
74
			for (RelativeResolver relative : relativeResolvers) {
75 2 1. getRelativeResolversFor : negated conditional → NO_COVERAGE
2. getRelativeResolversFor : negated conditional → KILLED
				if (resolverClass.isAssignableFrom(relative.getActualResourceResolver().getClass())) {
76
					found.add(relative);
77
				}
78
			}
79
		}
80 2 1. getRelativeResolversFor : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::getRelativeResolversFor → NO_COVERAGE
2. getRelativeResolversFor : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::getRelativeResolversFor → SURVIVED
		return found;
81
	}
82
83
	@SuppressWarnings("unchecked")
84
	private static <T> Set<T> findResolvers(ResourceResolver resolver, Class<T> resolverClass) {
85
		Set<T> found = new HashSet<>();
86 2 1. findResolvers : negated conditional → NO_COVERAGE
2. findResolvers : negated conditional → KILLED
		if (resolverClass.isAssignableFrom(resolver.getClass())) {
87
			found.add((T) resolver);
88
		}
89 2 1. findResolvers : negated conditional → SURVIVED
2. findResolvers : negated conditional → NO_COVERAGE
		if (resolver instanceof FirstSupportingResourceResolver) {
90
			found.addAll(findResolvers((FirstSupportingResourceResolver) resolver, resolverClass));
91
		}
92 2 1. findResolvers : negated conditional → NO_COVERAGE
2. findResolvers : negated conditional → KILLED
		if (resolver instanceof RelativeResolver) {
93
			found.addAll(findResolvers((RelativeResolver) resolver, resolverClass));
94
		}
95 2 1. findResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → SURVIVED
2. findResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → NO_COVERAGE
		return found;
96
	}
97
98
	@SuppressWarnings("unchecked")
99
	private static <T> Set<T> findResolvers(FirstSupportingResourceResolver resolver, Class<T> resolverClass) {
100
		try {
101
			Set<T> found = new HashSet<>();
102
			List<ResourceResolver> subresolvers = (List<ResourceResolver>) FieldUtils.readField(resolver, "resolvers", true);
103
			for (ResourceResolver r : subresolvers) {
104
				found.addAll(findResolvers(r, resolverClass));
105
			}
106 2 1. findResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → SURVIVED
2. findResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → NO_COVERAGE
			return found;
107
		} catch (IllegalAccessException e) {
108
			throw new IllegalStateException("Failed to get 'resolvers' field of FirstSupportingResourceResolver", e);
109
		}
110
	}
111
112
	@SuppressWarnings("unchecked")
113
	private static <T> Set<T> findResolvers(RelativeResolver resolver, Class<T> resolverClass) {
114
		try {
115
			Set<T> found = new HashSet<>();
116 2 1. findResolvers : negated conditional → NO_COVERAGE
2. findResolvers : negated conditional → SURVIVED
			if (resolverClass.isAssignableFrom(resolver.getClass())) {
117
				found.add((T) resolver);
118
			}
119
			ResourceResolver delegate = (ResourceResolver) FieldUtils.readField(resolver, "delegate", true);
120 2 1. findResolvers : negated conditional → NO_COVERAGE
2. findResolvers : negated conditional → KILLED
			if (resolverClass.isAssignableFrom(resolver.getActualResourceResolver().getClass())) {
121
				found.add((T) delegate);
122
			}
123 2 1. findResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → NO_COVERAGE
2. findResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → SURVIVED
			return found;
124
		} catch (IllegalAccessException e) {
125
			throw new IllegalStateException("Failed to get 'delegate' field of RelativeResolver", e);
126
		}
127
	}
128
129
}

Mutations

51

1.1
Location : classpath
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::classpath → NO_COVERAGE

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

67

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

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

75

1.1
Location : getRelativeResolversFor
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getRelativeResolversFor
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
negated conditional → KILLED

80

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

2.2
Location : getRelativeResolversFor
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::getRelativeResolversFor → SURVIVED

86

1.1
Location : findResolvers
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
negated conditional → KILLED

2.2
Location : findResolvers
Killed by : none
negated conditional → NO_COVERAGE

89

1.1
Location : findResolvers
Killed by : none
negated conditional → SURVIVED

2.2
Location : findResolvers
Killed by : none
negated conditional → NO_COVERAGE

92

1.1
Location : findResolvers
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
negated conditional → KILLED

2.2
Location : findResolvers
Killed by : none
negated conditional → NO_COVERAGE

95

1.1
Location : findResolvers
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → SURVIVED

2.2
Location : findResolvers
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → NO_COVERAGE

106

1.1
Location : findResolvers
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → SURVIVED

2.2
Location : findResolvers
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → NO_COVERAGE

116

1.1
Location : findResolvers
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : findResolvers
Killed by : none
negated conditional → SURVIVED

120

1.1
Location : findResolvers
Killed by : oghamall.it.configuration.ThymeleafConfigurationTest.asDeveloperIDefineCustomPathPrefixInMyOwnCode(oghamall.it.configuration.ThymeleafConfigurationTest)
negated conditional → KILLED

2.2
Location : findResolvers
Killed by : none
negated conditional → NO_COVERAGE

123

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

2.2
Location : findResolvers
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ResourceResolverAssertions::findResolvers → SURVIVED

Active mutators

Tests examined


Report generated by PIT OGHAM