ResourceUtils.java

1
package fr.sii.ogham.testing.util;
2
3
import java.io.FileNotFoundException;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.nio.charset.Charset;
7
import java.nio.charset.StandardCharsets;
8
9
import org.apache.commons.io.IOUtils;
10
11
/**
12
 * Contains utility methods to load resources in tests.
13
 * 
14
 * @author Aurélien Baudet
15
 *
16
 */
17
public final class ResourceUtils {
18
19
	/**
20
	 * Utility method that loads a file content from the classpath. UTF-8
21
	 * charset is used.
22
	 * 
23
	 * @param path
24
	 *            the path to the classpath resource
25
	 * @return the content of the file
26
	 * @throws IOException
27
	 *             when resource can't be read or doesn't exist
28
	 */
29
	public static String resourceAsString(String path) throws IOException {
30 6 1. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → NO_COVERAGE
2. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → TIMED_OUT
3. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
4. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
5. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
6. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
		return resourceAsString(path, StandardCharsets.UTF_8);
31
	}
32
33
	/**
34
	 * Utility method that loads a file content from the classpath.
35
	 * 
36
	 * @param path
37
	 *            the path to the classpath resource
38
	 * @param charset
39
	 *            the charset used for reading the file
40
	 * @return the content of the file
41
	 * @throws IOException
42
	 *             when resource can't be read or doesn't exist
43
	 */
44
	public static String resourceAsString(String path, Charset charset) throws IOException {
45 8 1. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → NO_COVERAGE
2. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → TIMED_OUT
3. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
4. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
5. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
6. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
7. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
8. resourceAsString : replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED
		return IOUtils.toString(resource(path), charset.name());
46
	}
47
48
	/**
49
	 * Utility method that loads a file content from the classpath.
50
	 * 
51
	 * @param path
52
	 *            the path to the classpath resource
53
	 * @return the content of the file as byte array
54
	 * @throws IOException
55
	 *             when resource can't be read or doesn't exist
56
	 */
57
	public static byte[] resource(String path) throws IOException {
58 9 1. resource : negated conditional → NO_COVERAGE
2. resource : negated conditional → TIMED_OUT
3. resource : negated conditional → KILLED
4. resource : negated conditional → KILLED
5. resource : negated conditional → KILLED
6. resource : negated conditional → KILLED
7. resource : negated conditional → KILLED
8. resource : negated conditional → KILLED
9. resource : negated conditional → KILLED
		InputStream resource = ResourceUtils.class.getClassLoader().getResourceAsStream(path.startsWith("/") ? path.substring(1) : path);
59 9 1. resource : negated conditional → NO_COVERAGE
2. resource : negated conditional → TIMED_OUT
3. resource : negated conditional → KILLED
4. resource : negated conditional → KILLED
5. resource : negated conditional → KILLED
6. resource : negated conditional → KILLED
7. resource : negated conditional → KILLED
8. resource : negated conditional → KILLED
9. resource : negated conditional → KILLED
		if (resource == null) {
60
			throw new FileNotFoundException("No resource found for path '" + path + "'");
61
		}
62 9 1. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → NO_COVERAGE
2. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → TIMED_OUT
3. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
4. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
5. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
6. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
7. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
8. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
9. resource : replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED
		return IOUtils.toByteArray(resource);
63
	}
64
65
	private ResourceUtils() {
66
		super();
67
	}
68
69
}

Mutations

30

1.1
Location : resourceAsString
Killed by : oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest.noStyles(oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

2.2
Location : resourceAsString
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → NO_COVERAGE

3.3
Location : resourceAsString
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

4.4
Location : resourceAsString
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

5.5
Location : resourceAsString
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → TIMED_OUT

6.6
Location : resourceAsString
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipExternalImages(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

45

1.1
Location : resourceAsString
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipExternalImages(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

2.2
Location : resourceAsString
Killed by : oghamtesting.it.assertion.AssertTemplateSpec
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

3.3
Location : resourceAsString
Killed by : oghamfremarker.it.FreeMarkerParserTest.nested(oghamfremarker.it.FreeMarkerParserTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

4.4
Location : resourceAsString
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → TIMED_OUT

5.5
Location : resourceAsString
Killed by : none
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → NO_COVERAGE

6.6
Location : resourceAsString
Killed by : oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest.noStyles(oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

7.7
Location : resourceAsString
Killed by : oghamthymeleafv3.it.ThymeleafParserTest.html(oghamthymeleafv3.it.ThymeleafParserTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

8.8
Location : resourceAsString
Killed by : oghamthymeleafv2.it.ThymeleafParserTest.text(oghamthymeleafv2.it.ThymeleafParserTest)
replaced return value with "" for fr/sii/ogham/testing/util/ResourceUtils::resourceAsString → KILLED

58

1.1
Location : resource
Killed by : oghamtesting.it.assertion.AssertTemplateSpec
negated conditional → KILLED

2.2
Location : resource
Killed by : oghamfremarker.it.FreeMarkerParserTest.nested(oghamfremarker.it.FreeMarkerParserTest)
negated conditional → KILLED

3.3
Location : resource
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
negated conditional → KILLED

4.4
Location : resource
Killed by : none
negated conditional → NO_COVERAGE

5.5
Location : resource
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

6.6
Location : resource
Killed by : none
negated conditional → TIMED_OUT

7.7
Location : resource
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBodyWithAttachments(oghamjavamail.it.JavaMailStructureTest)
negated conditional → KILLED

8.8
Location : resource
Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.file(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest)
negated conditional → KILLED

9.9
Location : resource
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

59

1.1
Location : resource
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : resource
Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.file(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest)
negated conditional → KILLED

3.3
Location : resource
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBodyWithAttachments(oghamjavamail.it.JavaMailStructureTest)
negated conditional → KILLED

4.4
Location : resource
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

5.5
Location : resource
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

6.6
Location : resource
Killed by : oghamfremarker.it.FreeMarkerParserTest.nested(oghamfremarker.it.FreeMarkerParserTest)
negated conditional → KILLED

7.7
Location : resource
Killed by : none
negated conditional → NO_COVERAGE

8.8
Location : resource
Killed by : oghamtesting.it.assertion.AssertTemplateSpec
negated conditional → KILLED

9.9
Location : resource
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
negated conditional → KILLED

62

1.1
Location : resource
Killed by : none
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → NO_COVERAGE

2.2
Location : resource
Killed by : oghamcore.it.core.resource.resolver.FirstSupportingResolverTest.file(oghamcore.it.core.resource.resolver.FirstSupportingResolverTest)
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

3.3
Location : resource
Killed by : none
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → TIMED_OUT

4.4
Location : resource
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBodyWithAttachments(oghamjavamail.it.JavaMailStructureTest)
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

5.5
Location : resource
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

6.6
Location : resource
Killed by : oghamfremarker.it.FreeMarkerParserTest.nested(oghamfremarker.it.FreeMarkerParserTest)
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

7.7
Location : resource
Killed by : oghamtesting.it.assertion.AssertTemplateSpec
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

8.8
Location : resource
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

9.9
Location : resource
Killed by : oghamthymeleafv2.it.resolver.StringResourceResolverTest.text(oghamthymeleafv2.it.resolver.StringResourceResolverTest)
replaced return value with null for fr/sii/ogham/testing/util/ResourceUtils::resource → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM