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 2.2 3.3 |
|
28 |
1.1 2.2 3.3 |
|
37 |
1.1 2.2 |
|
38 |
1.1 2.2 |
|
47 |
1.1 2.2 |
|
48 |
1.1 2.2 |
|
51 |
1.1 2.2 |
|
57 |
1.1 2.2 |
|
58 |
1.1 2.2 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |
|
96 |
1.1 |