Compare commits

..

2 Commits

  1. 1
      Application_Properties.java
  2. 26
      pom.xml
  3. 1
      src/main/java/de/kreth/property2java/Generator.java
  4. 4
      src/main/java/de/kreth/property2java/processor/ProcessorConfiguration.java
  5. 20
      src/test/java/de/kreth/property2java/GeneratorTests.java
  6. 55
      src/test/java/de/kreth/property2java/processor/ProcessorConfigurationTest.java

@ -23,22 +23,22 @@
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.18.0</version> <version>3.20.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId> <artifactId>commons-text</artifactId>
<version>1.12.0</version> <version>1.15.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.8.0</version> <version>1.11.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.freemarker</groupId> <groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId> <artifactId>freemarker</artifactId>
<version>2.3.33</version> <version>2.3.34</version>
</dependency> </dependency>
<!-- LOGGING --> <!-- LOGGING -->
@ -50,7 +50,7 @@
<dependency> <dependency>
<groupId>jakarta.annotation</groupId> <groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId> <artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version> <version>3.0.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -76,43 +76,43 @@
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-RC1</version> <version>6.1.0-M1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>5.11.0-RC1</version> <version>6.1.0-M1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId> <artifactId>junit-jupiter-params</artifactId>
<version>5.11.0-RC1</version> <version>6.1.0-M1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.platform</groupId> <groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId> <artifactId>junit-platform-launcher</artifactId>
<version>1.11.0-RC1</version> <version>6.1.0-M1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.platform</groupId> <groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId> <artifactId>junit-platform-runner</artifactId>
<version>1.11.0-RC1</version> <version>1.14.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>5.12.0</version> <version>5.21.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<version>5.12.0</version> <version>5.21.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -124,7 +124,7 @@
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<version>3.26.3</version> <version>4.0.0-M1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

@ -69,7 +69,6 @@ public class Generator {
void generate(Properties properties, Writer out, String fileName, Configuration config) void generate(Properties properties, Writer out, String fileName, Configuration config)
throws IOException, TemplateException { throws IOException, TemplateException {
Map<String, Object> root = new HashMap<>(); Map<String, Object> root = new HashMap<>();
root.put("generator_name", getClass().getName()); root.put("generator_name", getClass().getName());
root.put("generation_date", dateTimeInstance.format(new Date())); root.put("generation_date", dateTimeInstance.format(new Date()));

@ -91,7 +91,7 @@ public class ProcessorConfiguration implements Configuration {
} }
static final class Builder { static final class Builder {
public GeneratorOptions[] options; private GeneratorOptions[] options;
private final Filer filer; private final Filer filer;
private final Element element; private final Element element;
private final List<String> resourcenames; private final List<String> resourcenames;
@ -113,7 +113,7 @@ public class ProcessorConfiguration implements Configuration {
return this; return this;
} }
public Builder addAll(String[] resourceNames) { public Builder addAll(String... resourceNames) {
this.resourcenames.addAll(Arrays.asList(resourceNames)); this.resourcenames.addAll(Arrays.asList(resourceNames));
return this; return this;
} }

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -205,6 +206,24 @@ class GeneratorTests {
assertThat(ex.getCause()).isInstanceOf(TemplateException.class); assertThat(ex.getCause()).isInstanceOf(TemplateException.class);
} }
@Test
void testGenerateProp() throws IOException, TemplateException {
Template template = mock(Template.class);
Properties properties = new Properties();
StringWriter out = new StringWriter();
Generator generator = new Generator(config, template);
String fileName = "de.kreth.messages.properties";
generator.generate(properties, out, fileName , config);
@SuppressWarnings("unchecked")
ArgumentCaptor<Map<String, Object>> dataModelCaptor = ArgumentCaptor.forClass(Map.class);
verify(template).process(dataModelCaptor.capture(), any(Writer.class));
assertThat(dataModelCaptor.getValue())
.containsEntry("bundle_base_name", "de.kreth.messages")
.containsEntry("fileName", fileName)
.containsEntry("classname", "De_Kreth_Messages_Properties");
}
@Test @Test
void testMainMethod() throws IOException, GeneratorException { void testMainMethod() throws IOException, GeneratorException {
Path source = Files.createTempFile(getClass().getSimpleName(), ".properties"); Path source = Files.createTempFile(getClass().getSimpleName(), ".properties");
@ -243,4 +262,5 @@ class GeneratorTests {
return line.contains("\t" + key + " "); return line.contains("\t" + key + " ");
} }
} }

@ -0,0 +1,55 @@
package de.kreth.property2java.processor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.io.StringReader;
import javax.annotation.processing.Filer;
import javax.lang.model.element.Name;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import de.kreth.property2java.Format;
@ExtendWith(MockitoExtension.class)
public class ProcessorConfigurationTest {
@Mock
private Filer filer;
@Mock
private TypeElement element;
@Test
void testPackage() throws IOException {
PackageElement packageElement = mock(PackageElement.class);
Name name = mock(Name.class);
String packageName = "de.kreth.pack.name";
String resourceName = "localization.properties";
FileObject fileObject = mock(FileObject.class);
StringReader input = new StringReader("key1=value1\n"
+ "key2=value2");
when(element.getEnclosingElement()).thenReturn(packageElement);
when(packageElement.getQualifiedName()).thenReturn(name);
when(name.toString()).thenReturn(packageName);
when(filer.getResource(StandardLocation.CLASS_PATH, "", resourceName)).thenReturn(fileObject);
when(fileObject.openReader(false)).thenReturn(input);
ProcessorConfiguration config = new ProcessorConfiguration(
ProcessorConfiguration.builder(filer, element)
.withFormat(Format.WithInnerPropertyLoader)
.addAll(resourceName));
assertThat(config.getPackage()).isEqualTo(packageName);
}
}
Loading…
Cancel
Save