|
|
|
@ -6,19 +6,21 @@ import static org.hamcrest.MatcherAssert.assertThat; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.anyString; |
|
|
|
import static org.mockito.ArgumentMatchers.anyString; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
import static org.mockito.Mockito.never; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.Reader; |
|
|
|
import java.io.Reader; |
|
|
|
import java.io.StringWriter; |
|
|
|
import java.io.StringWriter; |
|
|
|
import java.io.Writer; |
|
|
|
import java.io.Writer; |
|
|
|
|
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
|
|
|
import java.nio.file.Path; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.EnumSet; |
|
|
|
import java.util.EnumSet; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
@ -28,6 +30,8 @@ import java.util.Optional; |
|
|
|
import java.util.StringTokenizer; |
|
|
|
import java.util.StringTokenizer; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.cli.MissingOptionException; |
|
|
|
import org.hamcrest.Matchers; |
|
|
|
import org.hamcrest.Matchers; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
@ -45,7 +49,7 @@ import freemarker.template.TemplateException; |
|
|
|
@MockitoSettings(strictness = Strictness.LENIENT) |
|
|
|
@MockitoSettings(strictness = Strictness.LENIENT) |
|
|
|
class GeneratorTests { |
|
|
|
class GeneratorTests { |
|
|
|
|
|
|
|
|
|
|
|
private String path = "application.properties"; |
|
|
|
private final String path = "application.properties"; |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private Configuration config; |
|
|
|
private Configuration config; |
|
|
|
@ -189,6 +193,38 @@ class GeneratorTests { |
|
|
|
assertLineMatch(lines, "message_invoiceitem_allfieldsmustbeset", "message.invoiceitem.allfieldsmustbeset"); |
|
|
|
assertLineMatch(lines, "message_invoiceitem_allfieldsmustbeset", "message.invoiceitem.allfieldsmustbeset"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void testTemplateException() throws TemplateException, IOException { |
|
|
|
|
|
|
|
Template template = mock(Template.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when(config.outWriter(anyString())).thenReturn(mock(Writer.class)); |
|
|
|
|
|
|
|
doThrow(new TemplateException(null)).when(template).process(any(Map.class), any(Writer.class)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Generator generator = new Generator(config, template); |
|
|
|
|
|
|
|
GeneratorException ex = assertThrows(GeneratorException.class, generator::start); |
|
|
|
|
|
|
|
assertThat(ex.getCause()).isInstanceOf(TemplateException.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void testMainMethod() throws IOException, GeneratorException { |
|
|
|
|
|
|
|
Path source = Files.createTempFile(getClass().getSimpleName(), ".properties"); |
|
|
|
|
|
|
|
Generator.main(new String[]{"-t", "target", "-f", source.toString()}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void testMainMethodMissingOption() throws IOException, GeneratorException { |
|
|
|
|
|
|
|
IllegalStateException e = assertThrows(IllegalStateException.class, () -> Generator.main(new String[]{})); |
|
|
|
|
|
|
|
assertThat(e.getCause()).isInstanceOf(MissingOptionException.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void testGenerateFor() throws IOException, GeneratorException { |
|
|
|
|
|
|
|
Class<?> locationClass = getClass(); |
|
|
|
|
|
|
|
List<URL> rescources = new ArrayList<>(); |
|
|
|
|
|
|
|
String relativeTargetDir = "target"; |
|
|
|
|
|
|
|
Generator.generateFor(locationClass, rescources, relativeTargetDir); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertLineMatch(List<String> lines, String key, String expected) { |
|
|
|
private void assertLineMatch(List<String> lines, String key, String expected) { |
|
|
|
Optional<String> found = lines.stream().filter(line -> keyMatches(line, key)).findFirst(); |
|
|
|
Optional<String> found = lines.stream().filter(line -> keyMatches(line, key)).findFirst(); |
|
|
|
|
|
|
|
|
|
|
|
|