| 1 | package fr.sii.ogham.testing.assertion.internal; | |
| 2 | ||
| 3 | import static fr.sii.ogham.testing.assertion.util.AssertionHelper.assertThat; | |
| 4 | ||
| 5 | import java.util.Set; | |
| 6 | import java.util.stream.Collectors; | |
| 7 | ||
| 8 | import org.apache.commons.lang3.reflect.FieldUtils; | |
| 9 | import org.hamcrest.Matcher; | |
| 10 | import org.thymeleaf.TemplateEngine; | |
| 11 | ||
| 12 | import fr.sii.ogham.core.resource.resolver.ResourceResolver; | |
| 13 | import fr.sii.ogham.template.thymeleaf.common.ThymeleafParser; | |
| 14 | import fr.sii.ogham.testing.util.HasParent; | |
| 15 | ||
| 16 | /** | |
| 17 | * Helper class to make assertions on {@link ThymeleafParser} instance created | |
| 18 | * by Ogham. | |
| 19 | * | |
| 20 | * @author Aurélien Baudet | |
| 21 | * | |
| 22 | */ | |
| 23 | public class ThymeleafParserAssertions extends HasParent<ThymeleafAssertions> { | |
| 24 | private final Set<ThymeleafParser> parsers; | |
| 25 | ||
| 26 | public ThymeleafParserAssertions(ThymeleafAssertions parent, Set<ThymeleafParser> parsers) { | |
| 27 | super(parent); | |
| 28 | this.parsers = parsers; | |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * Ensures that {@link TemplateEngine} is configured as expected. | |
| 33 | * | |
| 34 | * @param matcher | |
| 35 | * the matcher to ensure that engine is configured as expected. | |
| 36 | * @return this instance for fluent chaining | |
| 37 | */ | |
| 38 | public ThymeleafParserAssertions engine(Matcher<? super TemplateEngine> matcher) { | |
| 39 | for (ThymeleafParser thymeleafParser : parsers) { | |
| 40 |
2
1. engine : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. engine : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → TIMED_OUT |
assertThat(getEngine(thymeleafParser), matcher); |
| 41 | } | |
| 42 |
2
1. engine : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::engine → NO_COVERAGE 2. engine : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::engine → TIMED_OUT |
return this; |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Make assertions on resource resolution. | |
| 47 | * | |
| 48 | * <pre> | |
| 49 | * {@code | |
| 50 | * resourceResolver() | |
| 51 | * .classpath() | |
| 52 | * .pathPrefix(is("prefix/") | |
| 53 | * } | |
| 54 | * </pre> | |
| 55 | * | |
| 56 | * @return builder for fluent chaining | |
| 57 | */ | |
| 58 | public ResourceResolverAssertions<ThymeleafParserAssertions> resourceResolver() { | |
| 59 |
2
1. resourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::resourceResolver → NO_COVERAGE 2. resourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::resourceResolver → KILLED |
return new ResourceResolverAssertions<>(this, getResourceResolvers()); |
| 60 | } | |
| 61 | ||
| 62 | private Set<ResourceResolver> getResourceResolvers() { | |
| 63 |
2
1. getResourceResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getResourceResolvers → NO_COVERAGE 2. getResourceResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getResourceResolvers → SURVIVED |
return parsers.stream() |
| 64 | .map(ThymeleafParserAssertions::getResourceResolver) | |
| 65 | .collect(Collectors.toSet()); | |
| 66 | } | |
| 67 | ||
| 68 | private static TemplateEngine getEngine(ThymeleafParser parser) { | |
| 69 | try { | |
| 70 |
3
1. getEngine : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getEngine → NO_COVERAGE 2. getEngine : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getEngine → TIMED_OUT 3. getEngine : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getEngine → KILLED |
return (TemplateEngine) FieldUtils.readField(parser, "engine", true); |
| 71 | } catch (IllegalAccessException e) { | |
| 72 | throw new IllegalStateException("Failed to get 'engine' field of ThymeleafParser", e); | |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 76 | private static ResourceResolver getResourceResolver(ThymeleafParser parser) { | |
| 77 | try { | |
| 78 |
2
1. getResourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getResourceResolver → NO_COVERAGE 2. getResourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/ThymeleafParserAssertions::getResourceResolver → KILLED |
return (ResourceResolver) FieldUtils.readField(parser, "resolver", true); |
| 79 | } catch (IllegalAccessException e) { | |
| 80 | throw new IllegalStateException("Failed to get 'resolver' field of ThymeleafParser", e); | |
| 81 | } | |
| 82 | } | |
| 83 | } | |
Mutations | ||
| 40 |
1.1 2.2 |
|
| 42 |
1.1 2.2 |
|
| 59 |
1.1 2.2 |
|
| 63 |
1.1 2.2 |
|
| 70 |
1.1 2.2 3.3 |
|
| 78 |
1.1 2.2 |