| 1 | package fr.sii.ogham.testing.assertion.template; | |
| 2 | ||
| 3 | import static fr.sii.ogham.testing.util.ResourceUtils.resourceAsString; | |
| 4 | ||
| 5 | import java.io.IOException; | |
| 6 | import java.nio.charset.Charset; | |
| 7 | ||
| 8 | import org.junit.Assert; | |
| 9 | ||
| 10 | import fr.sii.ogham.testing.assertion.util.AssertionRegistry; | |
| 11 | import fr.sii.ogham.testing.assertion.util.Executable; | |
| 12 | import fr.sii.ogham.testing.assertion.util.FailAtEndRegistry; | |
| 13 | ||
| 14 | /** | |
| 15 | * Assertion class that simplifies checking template content. | |
| 16 | * | |
| 17 | * @author Aurélien Baudet | |
| 18 | * | |
| 19 | */ | |
| 20 | public final class AssertTemplate { | |
| 21 | /** | |
| 22 | * Assert that the received content is same as the expected content. The | |
| 23 | * check is strict (totally identical even new line characters). The expected content is loaded | |
| 24 | * from the classpath. | |
| 25 | * | |
| 26 | * @param expectedContentPath | |
| 27 | * the path to the expected content available in the classpath | |
| 28 | * @param content | |
| 29 | * the received content to check | |
| 30 | * @throws IOException | |
| 31 | * when the expected content couldn't be read | |
| 32 | */ | |
| 33 | public static void assertEquals(String expectedContentPath, Object content) throws IOException { | |
| 34 | AssertionRegistry registry = new FailAtEndRegistry(); | |
| 35 |
3
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → SURVIVED 3. assertEquals : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → KILLED |
assertEquals(loadOrNull(expectedContentPath, registry), content, true, registry); |
| 36 |
3
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → SURVIVED 3. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * Assert that the received content is same as the expected content. The | |
| 41 | * check is permissive (new line characters are ignored). The expected | |
| 42 | * content is loaded from the classpath. | |
| 43 | * | |
| 44 | * @param expectedContentPath | |
| 45 | * the path to the expected content available in the classpath | |
| 46 | * @param content | |
| 47 | * the received content to check | |
| 48 | * @throws IOException | |
| 49 | * when the expected content couldn't be read | |
| 50 | */ | |
| 51 | public static void assertSimilar(String expectedContentPath, Object content) throws IOException { | |
| 52 | AssertionRegistry registry = new FailAtEndRegistry(); | |
| 53 |
2
1. assertSimilar : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → NO_COVERAGE 2. assertSimilar : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → KILLED |
assertEquals(loadOrNull(expectedContentPath, registry), content, false, registry); |
| 54 |
2
1. assertSimilar : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertSimilar : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Assert that the received content is same as the expected content. The | |
| 59 | * check is strict (totally identical even new line characters). | |
| 60 | * | |
| 61 | * @param expectedContent | |
| 62 | * the expected content | |
| 63 | * @param content | |
| 64 | * the received content to check | |
| 65 | */ | |
| 66 | public static void assertEquals(String expectedContent, String content) { | |
| 67 | AssertionRegistry registry = new FailAtEndRegistry(); | |
| 68 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → KILLED |
assertEquals(expectedContent, content, true, registry); |
| 69 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Assert that the received content is same as the expected content. The | |
| 74 | * check is permissive (new line characters are ignored). | |
| 75 | * | |
| 76 | * @param expectedContent | |
| 77 | * the expected content | |
| 78 | * @param content | |
| 79 | * the received content to check | |
| 80 | */ | |
| 81 | public static void assertSimilar(String expectedContent, String content) { | |
| 82 | AssertionRegistry registry = new FailAtEndRegistry(); | |
| 83 |
2
1. assertSimilar : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → NO_COVERAGE 2. assertSimilar : removed call to fr/sii/ogham/testing/assertion/template/AssertTemplate::assertEquals → KILLED |
assertEquals(expectedContent, content, false, registry); |
| 84 |
2
1. assertSimilar : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertSimilar : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
| 85 | } | |
| 86 | | |
| 87 | private static void assertEquals(String expectedContent, Object content, boolean strict, AssertionRegistry registry) { | |
| 88 |
5
1. assertEquals : negated conditional → NO_COVERAGE 2. assertEquals : negated conditional → KILLED 3. assertEquals : negated conditional → KILLED 4. assertEquals : negated conditional → KILLED 5. assertEquals : negated conditional → KILLED |
String expected = strict ? expectedContent : sanitize(expectedContent); |
| 89 |
5
1. assertEquals : negated conditional → NO_COVERAGE 2. assertEquals : negated conditional → KILLED 3. assertEquals : negated conditional → KILLED 4. assertEquals : negated conditional → KILLED 5. assertEquals : negated conditional → KILLED |
String contentAsString = content==null ? null : content.toString(); |
| 90 |
5
1. assertEquals : negated conditional → NO_COVERAGE 2. assertEquals : negated conditional → KILLED 3. assertEquals : negated conditional → KILLED 4. assertEquals : negated conditional → KILLED 5. assertEquals : negated conditional → KILLED |
String actual = strict ? contentAsString : sanitize(contentAsString); |
| 91 |
16
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$0 : negated conditional → NO_COVERAGE 4. lambda$assertEquals$0 : negated conditional → NO_COVERAGE 5. lambda$assertEquals$0 : removed call to org/junit/Assert::assertEquals → SURVIVED 6. lambda$assertEquals$0 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 7. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 8. lambda$assertEquals$0 : negated conditional → KILLED 9. lambda$assertEquals$0 : negated conditional → KILLED 10. lambda$assertEquals$0 : negated conditional → KILLED 11. lambda$assertEquals$0 : negated conditional → KILLED 12. lambda$assertEquals$0 : negated conditional → KILLED 13. lambda$assertEquals$0 : negated conditional → KILLED 14. lambda$assertEquals$0 : negated conditional → KILLED 15. lambda$assertEquals$0 : negated conditional → KILLED 16. lambda$assertEquals$0 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("parsed template is different to expected content", expected == null ? null : expected.replace("\r", ""), actual == null ? null : actual.replace("\r", ""))); |
| 92 | } | |
| 93 | | |
| 94 | private static String loadOrNull(String path, AssertionRegistry registry) throws IOException { | |
| 95 |
5
1. loadOrNull : negated conditional → NO_COVERAGE 2. loadOrNull : negated conditional → KILLED 3. loadOrNull : negated conditional → KILLED 4. loadOrNull : negated conditional → KILLED 5. loadOrNull : negated conditional → KILLED |
if (path == null) { |
| 96 |
2
1. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → NO_COVERAGE 2. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → KILLED |
return null; |
| 97 | } | |
| 98 | try { | |
| 99 |
5
1. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → NO_COVERAGE 2. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → KILLED 3. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → KILLED 4. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → KILLED 5. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → KILLED |
return resourceAsString(path, Charset.defaultCharset()); |
| 100 | } catch (IOException e) { | |
| 101 |
2
1. loadOrNull : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. loadOrNull : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(failure(e)); |
| 102 |
2
1. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → NO_COVERAGE 2. loadOrNull : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::loadOrNull → KILLED |
return null; |
| 103 | } | |
| 104 | } | |
| 105 | | |
| 106 | private static <E extends Exception> Executable<E> failure(E exception) { | |
| 107 |
2
1. failure : replaced return value with null for fr/sii/ogham/testing/assertion/template/AssertTemplate::failure → NO_COVERAGE 2. failure : replaced return value with null for fr/sii/ogham/testing/assertion/template/AssertTemplate::failure → KILLED |
return new Executable<E>() { |
| 108 | @Override | |
| 109 | public void run() throws E { | |
| 110 | throw exception; | |
| 111 | } | |
| 112 | }; | |
| 113 | } | |
| 114 | ||
| 115 | private static String sanitize(String str) { | |
| 116 |
2
1. sanitize : negated conditional → NO_COVERAGE 2. sanitize : negated conditional → KILLED |
if (str == null) { |
| 117 |
2
1. sanitize : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::sanitize → NO_COVERAGE 2. sanitize : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::sanitize → KILLED |
return null; |
| 118 | } | |
| 119 |
2
1. sanitize : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::sanitize → NO_COVERAGE 2. sanitize : replaced return value with "" for fr/sii/ogham/testing/assertion/template/AssertTemplate::sanitize → KILLED |
return str.replaceAll("\r|\n", ""); |
| 120 | } | |
| 121 | | |
| 122 | private AssertTemplate() { | |
| 123 | super(); | |
| 124 | } | |
| 125 | } | |
Mutations | ||
| 35 |
1.1 2.2 3.3 |
|
| 36 |
1.1 2.2 3.3 |
|
| 53 |
1.1 2.2 |
|
| 54 |
1.1 2.2 |
|
| 68 |
1.1 2.2 |
|
| 69 |
1.1 2.2 |
|
| 83 |
1.1 2.2 |
|
| 84 |
1.1 2.2 |
|
| 88 |
1.1 2.2 3.3 4.4 5.5 |
|
| 89 |
1.1 2.2 3.3 4.4 5.5 |
|
| 90 |
1.1 2.2 3.3 4.4 5.5 |
|
| 91 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 14.14 15.15 16.16 |
|
| 95 |
1.1 2.2 3.3 4.4 5.5 |
|
| 96 |
1.1 2.2 |
|
| 99 |
1.1 2.2 3.3 4.4 5.5 |
|
| 101 |
1.1 2.2 |
|
| 102 |
1.1 2.2 |
|
| 107 |
1.1 2.2 |
|
| 116 |
1.1 2.2 |
|
| 117 |
1.1 2.2 |
|
| 119 |
1.1 2.2 |