run openrewrite

master
Markus Kreth 2 months ago
parent 3128f1fb46
commit 8e9671bec5
  1. 1
      Application_Properties.java
  2. 2
      pom.xml
  3. 1
      src/main/java/de/kreth/property2java/processor/GenerateProperty2Java.java
  4. 1
      src/main/java/de/kreth/property2java/processor/Property2JavaGenerator.java
  5. 3
      src/test/java/de/kreth/property2java/ConfigurationTest.java
  6. 13
      src/test/java/de/kreth/property2java/GeneratorTests.java
  7. 26
      src/test/java/de/kreth/property2java/processor/Property2JavaGeneratorTest.java

@ -146,7 +146,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version> <version>3.14.1</version>
<configuration> <configuration>
<release>${java.version}</release> <release>${java.version}</release>
<compilerArgs>-proc:none</compilerArgs> <compilerArgs>-proc:none</compilerArgs>

@ -6,6 +6,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import de.kreth.property2java.Format; import de.kreth.property2java.Format;
import de.kreth.property2java.GeneratorOptions; import de.kreth.property2java.GeneratorOptions;

@ -16,6 +16,7 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import de.kreth.property2java.Format; import de.kreth.property2java.Format;
import de.kreth.property2java.GeneratorException; import de.kreth.property2java.GeneratorException;
import de.kreth.property2java.GeneratorOptions; import de.kreth.property2java.GeneratorOptions;

@ -1,6 +1,7 @@
package de.kreth.property2java; package de.kreth.property2java;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

@ -30,6 +30,7 @@ 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.apache.commons.cli.MissingOptionException;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -198,24 +199,24 @@ class GeneratorTests {
when(config.outWriter(anyString())).thenReturn(mock(Writer.class)); when(config.outWriter(anyString())).thenReturn(mock(Writer.class));
doThrow(new TemplateException(null)).when(template).process(any(Map.class), any(Writer.class)); doThrow(new TemplateException(null)).when(template).process(any(Map.class), any(Writer.class));
Generator generator = new Generator(config, template); Generator generator = new Generator(config, template);
GeneratorException ex = assertThrows(GeneratorException.class, () -> generator.start()); GeneratorException ex = assertThrows(GeneratorException.class, generator::start);
assertThat(ex.getCause()).isInstanceOf(TemplateException.class); assertThat(ex.getCause()).isInstanceOf(TemplateException.class);
} }
@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");
Generator.main(new String[] {"-t", "target", "-f", source.toString()}); Generator.main(new String[]{"-t", "target", "-f", source.toString()});
} }
@Test @Test
void testMainMethodMissingOption() throws IOException, GeneratorException { void testMainMethodMissingOption() throws IOException, GeneratorException {
IllegalStateException e = assertThrows(IllegalStateException.class, () -> Generator.main(new String[] {})); IllegalStateException e = assertThrows(IllegalStateException.class, () -> Generator.main(new String[]{}));
assertThat(e.getCause()).isInstanceOf(MissingOptionException.class); assertThat(e.getCause()).isInstanceOf(MissingOptionException.class);
} }
@Test @Test
void testGenerateFor() throws IOException, GeneratorException { void testGenerateFor() throws IOException, GeneratorException {
Class<?> locationClass = getClass(); Class<?> locationClass = getClass();
@ -223,7 +224,7 @@ class GeneratorTests {
String relativeTargetDir = "target"; String relativeTargetDir = "target";
Generator.generateFor(locationClass, rescources, relativeTargetDir); 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();

@ -42,40 +42,40 @@ public class Property2JavaGeneratorTest {
when(processingEnv.getMessager()).thenReturn(messanger); when(processingEnv.getMessager()).thenReturn(messanger);
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({"unchecked", "rawtypes"})
@Test @Test
void testGeneratorInitializedCorrectly() { void testGeneratorInitializedCorrectly() {
GenerateProperty2Java an = mock(GenerateProperty2Java.class); GenerateProperty2Java an = mock(GenerateProperty2Java.class);
when(an.resources()).thenReturn(new String[] {}); when(an.resources()).thenReturn(new String[]{});
TypeElement element = mock(TypeElement.class); TypeElement element = mock(TypeElement.class);
when(element.getAnnotation(GenerateProperty2Java.class)).thenReturn(an); when(element.getAnnotation(GenerateProperty2Java.class)).thenReturn(an);
annotations.add(element); annotations.add(element);
when(roundEnv.getElementsAnnotatedWith(ArgumentMatchers.any(Class.class))).thenReturn(annotations); when(roundEnv.getElementsAnnotatedWith(ArgumentMatchers.any(Class.class))).thenReturn(annotations);
Element annotatedElement = mock(Element.class); Element annotatedElement = mock(Element.class);
GenerateResourceBundleProperty2Javas value = new GenerateResourceBundleProperty2Javas() { GenerateResourceBundleProperty2Javas value = new GenerateResourceBundleProperty2Javas() {
@Override @Override
public Class<? extends Annotation> annotationType() { public Class<? extends Annotation> annotationType() {
return null; return null;
} }
@Override @Override
public GenerateResourceBundleProperty2Java[] value() { public GenerateResourceBundleProperty2Java[] value() {
return new GenerateResourceBundleProperty2Java[0]; return new GenerateResourceBundleProperty2Java[0];
} }
}; };
when(annotatedElement.getAnnotation(GenerateResourceBundleProperty2Javas.class)).thenReturn(value ); when(annotatedElement.getAnnotation(GenerateResourceBundleProperty2Javas.class)).thenReturn(value);
Set<Element> elements = new HashSet<>(List.of(annotatedElement)); Set<Element> elements = new HashSet<>(List.of(annotatedElement));
when(roundEnv.getElementsAnnotatedWith(GenerateResourceBundleProperty2Javas.class)) when(roundEnv.getElementsAnnotatedWith(GenerateResourceBundleProperty2Javas.class))
.thenReturn((Set)elements); .thenReturn((Set) elements);
processor.process(annotations, roundEnv); processor.process(annotations, roundEnv);
} }
} }

Loading…
Cancel
Save