openrewrite reformat

master
Markus Kreth 2 weeks ago
parent 94fe827d29
commit e117902e21
  1. 1
      Application_Properties.java
  2. 2
      pom.xml
  3. 3
      src/main/java/de/kreth/property2java/Generator.java
  4. 2
      src/main/java/de/kreth/property2java/GeneratorOptions.java
  5. 20
      src/main/java/de/kreth/property2java/config/FreemarkerConfig.java
  6. 4
      src/test/java/de/kreth/property2java/ConfigurationTest.java
  7. 24
      src/test/java/de/kreth/property2java/GeneratorTests.java
  8. 8
      src/test/java/de/kreth/property2java/parts/ReplaceLogicForTemplateTest.java
  9. 6
      src/test/java/de/kreth/property2java/processor/ProcessorConfigurationTest.java
  10. 2
      src/test/java/de/kreth/property2java/processor/Property2JavaGeneratorTest.java

@ -203,6 +203,8 @@
<configuration>
<activeRecipes>
<recipe>org.openrewrite.maven.BestPractices</recipe>
<recipe>org.openrewrite.java.OrderImports</recipe>
<recipe>org.openrewrite.java.format.AutoFormat</recipe>
</activeRecipes>
<exclusions>
<exclusion>**/generated/**</exclusion>

@ -91,8 +91,7 @@ public class Generator {
root.put("entries", entries);
@SuppressWarnings("unchecked")
List<String> propertyNames = Collections.list((Enumeration<String>) properties.propertyNames());
@SuppressWarnings("unchecked") List<String> propertyNames = Collections.list((Enumeration<String>) properties.propertyNames());
Collections.sort(propertyNames);
for (String propertyKeyString : propertyNames) {

@ -15,7 +15,7 @@ public enum GeneratorOptions {
private final String[] additionalImport;
GeneratorOptions(String... additionalImport) {
this.additionalImport = additionalImport!= null ? additionalImport : new String[]{};
this.additionalImport = additionalImport != null ? additionalImport : new String[]{};
}
String[] getAdditionalImport() {

@ -16,16 +16,16 @@ public enum FreemarkerConfig {
public Template getTemplate(Format format) throws IOException {
switch (format) {
case WithInitializer:
return cfg.getTemplate("enum_template_with_initializer.tpl");
case WithInnerPropertyLoader:
return cfg.getTemplate("enum_template_with_inner_properties.tpl");
case WithInnerPropertyResourceBundle:
return cfg.getTemplate("enum_template_with_inner_propertyresourcebundle.tpl");
case WithUnaryOperatorParameter:
return cfg.getTemplate("enum_template.tpl");
default:
throw new IllegalArgumentException("Format " + format + " is not supported.");
case WithInitializer:
return cfg.getTemplate("enum_template_with_initializer.tpl");
case WithInnerPropertyLoader:
return cfg.getTemplate("enum_template_with_inner_properties.tpl");
case WithInnerPropertyResourceBundle:
return cfg.getTemplate("enum_template_with_inner_propertyresourcebundle.tpl");
case WithUnaryOperatorParameter:
return cfg.getTemplate("enum_template.tpl");
default:
throw new IllegalArgumentException("Format " + format + " is not supported.");
}
}

@ -1,6 +1,6 @@
package de.kreth.property2java;
import static org.junit.jupiter.api.Assertions.assertEquals;
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.Mockito.when;
@ -31,7 +31,7 @@ class ConfigurationTest {
when(config.outputCharset()).thenCallRealMethod();
Writer outWriter = config.outWriter("application.properties");
assertInstanceOf(FileWriter.class, outWriter);
assertInstanceOf(FileWriter.class, outWriter);
}
@Test

@ -79,17 +79,14 @@ class GeneratorTests {
StringWriter out = new StringWriter();
when(config.outWriter(anyString())).thenReturn(out);
@SuppressWarnings("unchecked")
ArgumentCaptor<Map<String, Object>> rootCaptior = ArgumentCaptor.forClass(Map.class);
@SuppressWarnings("unchecked") ArgumentCaptor<Map<String, Object>> rootCaptior = ArgumentCaptor.forClass(Map.class);
generator.start();
verify(template).process(rootCaptior.capture(), any(Writer.class));
Map<String, Object> root = rootCaptior.getValue();
@SuppressWarnings("unchecked")
EnumSet<GeneratorOptions> options = (EnumSet<GeneratorOptions>) root.get("options");
@SuppressWarnings("unchecked") EnumSet<GeneratorOptions> options = (EnumSet<GeneratorOptions>) root.get("options");
assertThat(options).contains(GeneratorOptions.WithMessageFormatter, GeneratorOptions.WithSubstitutors);
@SuppressWarnings("unchecked")
List<String> imports = (List<String>) root.get("imports");
@SuppressWarnings("unchecked") List<String> imports = (List<String>) root.get("imports");
assertThat(imports).contains("java.text.MessageFormat");
}
@ -103,13 +100,11 @@ class GeneratorTests {
StringWriter out = new StringWriter();
when(config.outWriter(anyString())).thenReturn(out);
@SuppressWarnings("unchecked")
ArgumentCaptor<Map<String, Object>> rootCaptior = ArgumentCaptor.forClass(Map.class);
@SuppressWarnings("unchecked") ArgumentCaptor<Map<String, Object>> rootCaptior = ArgumentCaptor.forClass(Map.class);
generator.start();
verify(template).process(rootCaptior.capture(), any(Writer.class));
Map<String, Object> root = rootCaptior.getValue();
@SuppressWarnings("unchecked")
EnumSet<GeneratorOptions> options = (EnumSet<GeneratorOptions>) root.get("options");
@SuppressWarnings("unchecked") EnumSet<GeneratorOptions> options = (EnumSet<GeneratorOptions>) root.get("options");
assertThat(options).contains(GeneratorOptions.WithSubstitutors);
assertFalse(root.containsKey("imports"));
@ -215,13 +210,12 @@ class GeneratorTests {
String fileName = "de.kreth.messages.properties";
generator.generate(properties, out, fileName, config);
@SuppressWarnings("unchecked")
ArgumentCaptor<Map<String, Object>> dataModelCaptor = ArgumentCaptor.forClass(Map.class);
@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");
.containsEntry("bundle_base_name", "de.kreth.messages")
.containsEntry("fileName", fileName)
.containsEntry("classname", "De_Kreth_Messages_Properties");
}
@Test

@ -76,10 +76,10 @@ public class ReplaceLogicForTemplateTest {
void testMissingReplacement() {
String property = "Start{1}End";
assertThatThrownBy(() -> doReplacements(property, "|0|"))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("{1}") // Orignal Placeholder
.hasMessageContaining("Position=5") // Index of missing Placeholder
.hasMessageContaining(property); // Orignal Text
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("{1}") // Orignal Placeholder
.hasMessageContaining("Position=5") // Index of missing Placeholder
.hasMessageContaining(property); // Orignal Text
}
}

@ -46,9 +46,9 @@ public class ProcessorConfigurationTest {
when(fileObject.openReader(false)).thenReturn(input);
ProcessorConfiguration config = new ProcessorConfiguration(
ProcessorConfiguration.builder(filer, element)
.withFormat(Format.WithInnerPropertyLoader)
.addAll(resourceName));
ProcessorConfiguration.builder(filer, element)
.withFormat(Format.WithInnerPropertyLoader)
.addAll(resourceName));
assertThat(config.getPackage()).isEqualTo(packageName);
}

@ -71,7 +71,7 @@ public class Property2JavaGeneratorTest {
Set<Element> elements = new HashSet<>(List.of(annotatedElement));
when(roundEnv.getElementsAnnotatedWith(GenerateResourceBundleProperty2Javas.class))
.thenReturn((Set) elements);
.thenReturn((Set) elements);
processor.process(annotations, roundEnv);

Loading…
Cancel
Save