| 1 | package fr.sii.ogham.testing.assertion.internal; | |
| 2 | ||
| 3 | import static java.util.stream.Collectors.toSet; | |
| 4 | import static org.apache.commons.lang3.reflect.FieldUtils.readField; | |
| 5 | ||
| 6 | import java.util.Set; | |
| 7 | import java.util.stream.Collectors; | |
| 8 | ||
| 9 | import org.apache.commons.lang3.reflect.FieldUtils; | |
| 10 | ||
| 11 | import fr.sii.ogham.core.resource.resolver.ResourceResolver; | |
| 12 | import fr.sii.ogham.template.freemarker.FreeMarkerParser; | |
| 13 | import fr.sii.ogham.testing.util.HasParent; | |
| 14 | import freemarker.template.Configuration; | |
| 15 | ||
| 16 | /** | |
| 17 | * Helper to make assertions on {@link FreeMarkerParser}. | |
| 18 | * | |
| 19 | * @author Aurélien Baudet | |
| 20 | * | |
| 21 | */ | |
| 22 | public class FreemarkerParserAssertions extends HasParent<FreemarkerAssersions> { | |
| 23 | private final Set<FreeMarkerParser> parsers; | |
| 24 | ||
| 25 | public FreemarkerParserAssertions(FreemarkerAssersions parent, Set<FreeMarkerParser> parsers) { | |
| 26 | super(parent); | |
| 27 | this.parsers = parsers; | |
| 28 | } | |
| 29 | ||
| 30 | /** | |
| 31 | * Make assertions on FreeMarker {@link Configuration} instance to ensure | |
| 32 | * that it is correctly configured. | |
| 33 | * | |
| 34 | * For example: | |
| 35 | * | |
| 36 | * <pre> | |
| 37 | * {@code | |
| 38 | * configuration() | |
| 39 | * .defaultEncoding(equalTo("UTF-8")) | |
| 40 | * } | |
| 41 | * </pre> | |
| 42 | * | |
| 43 | * @return builder for fluent chaining | |
| 44 | */ | |
| 45 | public FreemarkerConfigurationAssersions configuration() { | |
| 46 |
3
1. configuration : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::configuration → NO_COVERAGE 2. configuration : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::configuration → KILLED 3. configuration : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::configuration → KILLED |
return new FreemarkerConfigurationAssersions(this, parsers.stream().map(FreemarkerParserAssertions::getConfiguration).collect(toSet())); |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Make assertions on resource resolution. | |
| 51 | * | |
| 52 | * <pre> | |
| 53 | * {@code | |
| 54 | * resourceResolver() | |
| 55 | * .classpath() | |
| 56 | * .pathPrefix(is("prefix/") | |
| 57 | * } | |
| 58 | * </pre> | |
| 59 | * | |
| 60 | * @return builder for fluent chaining | |
| 61 | */ | |
| 62 | public ResourceResolverAssertions<FreemarkerParserAssertions> resourceResolver() { | |
| 63 |
2
1. resourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::resourceResolver → NO_COVERAGE 2. resourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::resourceResolver → KILLED |
return new ResourceResolverAssertions<>(this, getResourceResolvers()); |
| 64 | } | |
| 65 | | |
| 66 | private Set<ResourceResolver> getResourceResolvers() { | |
| 67 |
2
1. getResourceResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getResourceResolvers → NO_COVERAGE 2. getResourceResolvers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getResourceResolvers → SURVIVED |
return parsers.stream() |
| 68 | .map(FreemarkerParserAssertions::getResourceResolver) | |
| 69 | .collect(Collectors.toSet()); | |
| 70 | } | |
| 71 | ||
| 72 | ||
| 73 | private static Configuration getConfiguration(FreeMarkerParser freeMarkerParser) { | |
| 74 | try { | |
| 75 |
3
1. getConfiguration : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getConfiguration → NO_COVERAGE 2. getConfiguration : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getConfiguration → TIMED_OUT 3. getConfiguration : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getConfiguration → KILLED |
return (Configuration) readField(freeMarkerParser, "configuration", true); |
| 76 | } catch (IllegalAccessException e) { | |
| 77 | throw new IllegalArgumentException("Failed to read 'configuration' field of FreeMarkerParser", e); | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | private static ResourceResolver getResourceResolver(FreeMarkerParser parser) { | |
| 82 | try { | |
| 83 |
2
1. getResourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getResourceResolver → NO_COVERAGE 2. getResourceResolver : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerParserAssertions::getResourceResolver → KILLED |
return (ResourceResolver) FieldUtils.readField(parser, "resolver", true); |
| 84 | } catch (IllegalAccessException e) { | |
| 85 | throw new IllegalStateException("Failed to get 'resolver' field of FreeMarkerParser", e); | |
| 86 | } | |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 46 |
1.1 2.2 3.3 |
|
| 63 |
1.1 2.2 |
|
| 67 |
1.1 2.2 |
|
| 75 |
1.1 2.2 3.3 |
|
| 83 |
1.1 2.2 |