FilterableClassLoader.java

1
package fr.sii.ogham.testing.mock.classloader;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.net.URL;
6
import java.util.Collections;
7
import java.util.Enumeration;
8
import java.util.function.Predicate;
9
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12
13
public class FilterableClassLoader extends ClassLoader {
14
	private static final Logger LOG = LoggerFactory.getLogger(FilterableClassLoader.class);
15
	
16
	private ClassLoader delegate;
17
	private Predicate<String> predicate;
18
19
	public FilterableClassLoader(ClassLoader delegate, Predicate<String> predicate) {
20
		super();
21
		this.delegate = delegate;
22
		this.predicate = predicate;
23
	}
24
25
	@Override
26
	public Class<?> loadClass(String name) throws ClassNotFoundException {
27 3 1. loadClass : negated conditional → NO_COVERAGE
2. loadClass : negated conditional → KILLED
3. loadClass : negated conditional → KILLED
		if(predicate.test(name)) {
28 3 1. loadClass : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::loadClass → NO_COVERAGE
2. loadClass : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::loadClass → KILLED
3. loadClass : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::loadClass → KILLED
			return delegate.loadClass(name);
29
		} else {
30
			LOG.info("Class {} not accepted", name);
31
			throw new ClassNotFoundException("Class "+name+" not accepted");
32
		}
33
	}
34
35
	@Override
36
	public URL getResource(String name) {
37 2 1. getResource : negated conditional → NO_COVERAGE
2. getResource : negated conditional → KILLED
		if(predicate.test(name)) {
38 2 1. getResource : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResource → NO_COVERAGE
2. getResource : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResource → KILLED
			return delegate.getResource(name);
39
		} else {
40
			LOG.info("Resource {} not accepted", name);
41
			return null;
42
		}
43
	}
44
45
	@Override
46
	public Enumeration<URL> getResources(String name) throws IOException {
47 2 1. getResources : negated conditional → NO_COVERAGE
2. getResources : negated conditional → KILLED
		if(predicate.test(name)) {
48 2 1. getResources : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → NO_COVERAGE
2. getResources : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → KILLED
			return delegate.getResources(name);
49
		} else {
50
			LOG.info("Resources {} not accepted", name);
51 2 1. getResources : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → NO_COVERAGE
2. getResources : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → KILLED
			return Collections.emptyEnumeration();
52
		}
53
	}
54
55
	@Override
56
	public InputStream getResourceAsStream(String name) {
57 2 1. getResourceAsStream : negated conditional → NO_COVERAGE
2. getResourceAsStream : negated conditional → KILLED
		if(predicate.test(name)) {
58 2 1. getResourceAsStream : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResourceAsStream → NO_COVERAGE
2. getResourceAsStream : replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResourceAsStream → KILLED
			return delegate.getResourceAsStream(name);
59
		} else {
60
			LOG.info("Resource {} not accepted", name);
61
			return null;
62
		}
63
	}
64
65
	@Override
66
	public void setDefaultAssertionStatus(boolean enabled) {
67 1 1. setDefaultAssertionStatus : removed call to java/lang/ClassLoader::setDefaultAssertionStatus → NO_COVERAGE
		super.setDefaultAssertionStatus(enabled);
68 1 1. setDefaultAssertionStatus : negated conditional → NO_COVERAGE
		if (delegate != null) {
69 1 1. setDefaultAssertionStatus : removed call to java/lang/ClassLoader::setDefaultAssertionStatus → NO_COVERAGE
			delegate.setDefaultAssertionStatus(enabled);
70
		}
71
		// TODO: should set value when delegate is initialized ?
72
	}
73
74
	@Override
75
	public void setPackageAssertionStatus(String packageName, boolean enabled) {
76 1 1. setPackageAssertionStatus : removed call to java/lang/ClassLoader::setPackageAssertionStatus → NO_COVERAGE
		super.setPackageAssertionStatus(packageName, enabled);
77 1 1. setPackageAssertionStatus : negated conditional → NO_COVERAGE
		if (delegate != null) {
78 1 1. setPackageAssertionStatus : removed call to java/lang/ClassLoader::setPackageAssertionStatus → NO_COVERAGE
			delegate.setPackageAssertionStatus(packageName, enabled);
79
		}
80
		// TODO: should set values when delegate is initialized ?
81
	}
82
83
	@Override
84
	public void setClassAssertionStatus(String className, boolean enabled) {
85 1 1. setClassAssertionStatus : removed call to java/lang/ClassLoader::setClassAssertionStatus → NO_COVERAGE
		super.setClassAssertionStatus(className, enabled);
86 1 1. setClassAssertionStatus : negated conditional → NO_COVERAGE
		if (delegate != null) {
87 1 1. setClassAssertionStatus : removed call to java/lang/ClassLoader::setClassAssertionStatus → NO_COVERAGE
			delegate.setClassAssertionStatus(className, enabled);
88
		}
89
		// TODO: should set values when delegate is initialized ?
90
	}
91
92
	@Override
93
	public void clearAssertionStatus() {
94 1 1. clearAssertionStatus : removed call to java/lang/ClassLoader::clearAssertionStatus → NO_COVERAGE
		super.clearAssertionStatus();
95 1 1. clearAssertionStatus : negated conditional → NO_COVERAGE
		if (delegate != null) {
96 1 1. clearAssertionStatus : removed call to java/lang/ClassLoader::clearAssertionStatus → NO_COVERAGE
			delegate.clearAssertionStatus();
97
		}
98
		// TODO: should call when delegate is initialized ?
99
	}
100
	
101
	
102
}

Mutations

27

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

2.2
Location : loadClass
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
negated conditional → KILLED

3.3
Location : loadClass
Killed by : oghamall.it.optional.ImplementationSelectionTests.javaMailAvailable(oghamall.it.optional.ImplementationSelectionTests)
negated conditional → KILLED

28

1.1
Location : loadClass
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::loadClass → KILLED

2.2
Location : loadClass
Killed by : none
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::loadClass → NO_COVERAGE

3.3
Location : loadClass
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::loadClass → KILLED

37

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

2.2
Location : getResource
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
negated conditional → KILLED

38

1.1
Location : getResource
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResource → KILLED

2.2
Location : getResource
Killed by : none
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResource → NO_COVERAGE

47

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

2.2
Location : getResources
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
negated conditional → KILLED

48

1.1
Location : getResources
Killed by : none
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → NO_COVERAGE

2.2
Location : getResources
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → KILLED

51

1.1
Location : getResources
Killed by : none
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → NO_COVERAGE

2.2
Location : getResources
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResources → KILLED

57

1.1
Location : getResourceAsStream
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
negated conditional → KILLED

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

58

1.1
Location : getResourceAsStream
Killed by : none
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResourceAsStream → NO_COVERAGE

2.2
Location : getResourceAsStream
Killed by : oghamtesting.ut.mock.FilterableClassLoaderSpec
replaced return value with null for fr/sii/ogham/testing/mock/classloader/FilterableClassLoader::getResourceAsStream → KILLED

67

1.1
Location : setDefaultAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::setDefaultAssertionStatus → NO_COVERAGE

68

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

69

1.1
Location : setDefaultAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::setDefaultAssertionStatus → NO_COVERAGE

76

1.1
Location : setPackageAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::setPackageAssertionStatus → NO_COVERAGE

77

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

78

1.1
Location : setPackageAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::setPackageAssertionStatus → NO_COVERAGE

85

1.1
Location : setClassAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::setClassAssertionStatus → NO_COVERAGE

86

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

87

1.1
Location : setClassAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::setClassAssertionStatus → NO_COVERAGE

94

1.1
Location : clearAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::clearAssertionStatus → NO_COVERAGE

95

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

96

1.1
Location : clearAssertionStatus
Killed by : none
removed call to java/lang/ClassLoader::clearAssertionStatus → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM