From b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 3 Aug 2013 15:06:46 +0200 Subject: wip --- .../compiler/InMemoryJavaFileManager.java | 16 +++++++---- .../container/compiler/JavaSourceFromString.java | 1 - .../trygvis/container/compiler/ProcessorTest.java | 32 ++++++++++++++++------ .../io/trygvis/container/compiler/UtilsTest.java | 25 +++++++++++++++++ 4 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java (limited to 'container-compiler-plugin/src/test/java/io') diff --git a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java index e476d3e..60a78ae 100644 --- a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java +++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java @@ -13,11 +13,11 @@ import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.net.URI; -import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; public class InMemoryJavaFileManager extends ForwardingJavaFileManager { - public final Map codes = new HashMap<>(); + public final Map codes = new TreeMap<>(); public InMemoryJavaFileManager(StandardJavaFileManager standardFileManager) { super(standardFileManager); @@ -25,13 +25,11 @@ public class InMemoryJavaFileManager extends ForwardingJavaFileManager entry : fileManager.codes.entrySet()) { + System.out.println("=== " + entry.getKey()); + System.out.println(entry.getValue()); + } for (Diagnostic diagnostic : collector.getDiagnostics()) { -// System.out.println("diagnostic = " + diagnostic); System.out.println("diagnostic.source = ->" + diagnostic.getSource().getName() + "<-"); System.out.println("diagnostic.message = " + diagnostic.getMessage(Locale.ENGLISH)); } @@ -51,4 +58,13 @@ public class ProcessorTest { fileManager.close(); } + + private JavaSourceFromString loadCode(String className) throws IOException { + String path = "/" + className.replace('.', '/') + ".java"; + URL resource = getClass().getResource(path); + if(resource == null) { + throw new RuntimeException("Could not load code for: " + path); + } + return new JavaSourceFromString(className, IOUtils.toString(resource, UTF_8)); + } } diff --git a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java new file mode 100644 index 0000000..0dd1414 --- /dev/null +++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java @@ -0,0 +1,25 @@ +package io.trygvis.container.compiler; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static io.trygvis.container.compiler.Utils.toFieldName; +import static org.testng.Assert.assertEquals; + +public class UtilsTest { + @DataProvider(name = "toFieldName", parallel = true) + public static Object[][] SqlNameDataProvider() { + return new Object[][] { + new Object[]{"FooBar", "fooBar"}, + new Object[]{"fooBar", "fooBar"}, + new Object[]{"foo_bar", "fooBar"}, + new Object[]{"_foo_bar", "fooBar"}, + new Object[]{"foo_bar_", "fooBar"}, + }; + } + + @Test(dataProvider = "toFieldName") + public void testToFieldName(String input, String output) { + assertEquals(toFieldName(input), output); + } +} -- cgit v1.2.3