diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-11-27 07:18:48 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-11-27 07:18:48 +0100 |
commit | 4316e77e1eb6654eec18d04780a6da78c22fb644 (patch) | |
tree | 6c879d4190ee36f674c740e3755b46fb55098704 /test/delombok/src | |
parent | 391db3dcecdd0d94eb76b656e655346891b02bb4 (diff) | |
download | lombok-4316e77e1eb6654eec18d04780a6da78c22fb644.tar.gz lombok-4316e77e1eb6654eec18d04780a6da78c22fb644.tar.bz2 lombok-4316e77e1eb6654eec18d04780a6da78c22fb644.zip |
Added a class that is easier to use than the parser itself for delombok, as well as code to process entire directories at a time.
Also removed duplication from the testcases.
Diffstat (limited to 'test/delombok/src')
-rw-r--r-- | test/delombok/src/lombok/delombok/TestLombokFiles.java | 67 | ||||
-rw-r--r-- | test/delombok/src/lombok/delombok/TestSourceFiles.java | 76 |
2 files changed, 8 insertions, 135 deletions
diff --git a/test/delombok/src/lombok/delombok/TestLombokFiles.java b/test/delombok/src/lombok/delombok/TestLombokFiles.java index f04a0a34..1d93a4b2 100644 --- a/test/delombok/src/lombok/delombok/TestLombokFiles.java +++ b/test/delombok/src/lombok/delombok/TestLombokFiles.java @@ -21,77 +21,18 @@ */ package lombok.delombok; -import static org.junit.Assert.fail; -import static lombok.delombok.TestSourceFiles.removeBlanks; - -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringWriter; -import lombok.delombok.CommentPreservingParser.ParseResult; +import lombok.TestViaDelombok; -import org.junit.BeforeClass; import org.junit.Test; public class TestLombokFiles { - private static CommentPreservingParser parser; - - private static final File BEFORE_FOLDER = new File("test/lombok/resource/before"); - private static final File AFTER_FOLDER = new File("test/lombok/resource/after"); - - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - - @BeforeClass - public static void init() { - parser = new CommentPreservingParser(); - } + private static final File BEFORE_DIR = new File("test/lombok/resource/before"); + private static final File AFTER_DIR = new File("test/lombok/resource/after"); @Test public void testSources() throws Exception { - File[] listFiles = BEFORE_FOLDER.listFiles(); - for (File file : listFiles) { - ParseResult parseResult = parser.parse(file.toString(), true); - StringWriter writer = new StringWriter(); - parseResult.print(writer); - compare(file.getName(), readAfter(file), writer.toString()); - } - } - - private void compare(String name, String expectedFile, String actualFile) { - String[] expectedLines = expectedFile.split("(\\r?\\n)"); - String[] actualLines = actualFile.split("(\\r?\\n)"); - if (actualLines[0].startsWith("// Generated by delombok at ")) { - actualLines[0] = ""; - } - expectedLines = removeBlanks(expectedLines); - actualLines = removeBlanks(actualLines); - int size = Math.min(expectedLines.length, actualLines.length); - for (int i = 0; i < size; i++) { - String expected = expectedLines[i]; - String actual = actualLines[i]; - if (!expected.equals(actual)) { - fail(String.format("Difference in line %s(%d):\n`%s`\n`%s`\n", name, i, expected, actual)); - } - } - if (expectedLines.length > actualLines.length) { - fail(String.format("Missing line %s(%d): %s\n", name, size, expectedLines[size])); - } - if (expectedLines.length < actualLines.length) { - fail(String.format("Extra line %s(%d): %s\n", name, size, actualLines[size])); - } - } - - private String readAfter(File file) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File(AFTER_FOLDER, file.getName()))); - StringBuilder result = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - result.append(line); - result.append(LINE_SEPARATOR); - } - reader.close(); - return result.toString(); + TestViaDelombok.runComparison(BEFORE_DIR, AFTER_DIR); } } diff --git a/test/delombok/src/lombok/delombok/TestSourceFiles.java b/test/delombok/src/lombok/delombok/TestSourceFiles.java index 91ace773..a5df5197 100644 --- a/test/delombok/src/lombok/delombok/TestSourceFiles.java +++ b/test/delombok/src/lombok/delombok/TestSourceFiles.java @@ -21,86 +21,18 @@ */ package lombok.delombok; -import static org.junit.Assert.fail; - -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; -import lombok.delombok.CommentPreservingParser.ParseResult; +import lombok.TestViaDelombok; -import org.junit.BeforeClass; import org.junit.Test; public class TestSourceFiles { - private static CommentPreservingParser parser; - - private static final File BEFORE_FOLDER = new File("test/delombok/resource/before"); - private static final File AFTER_FOLDER = new File("test/delombok/resource/after"); - - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - - @BeforeClass - public static void init() { - parser = new CommentPreservingParser(); - } + private static final File BEFORE_DIR = new File("test/delombok/resource/before"); + private static final File AFTER_DIR = new File("test/delombok/resource/after"); @Test public void testSources() throws Exception { - File[] listFiles = BEFORE_FOLDER.listFiles(); - for (File file : listFiles) { - ParseResult parseResult = parser.parse(file.toString(), true); - StringWriter writer = new StringWriter(); - parseResult.print(writer); - compare(file.getName(), readAfter(file), writer.toString()); - } - } - - static String[] removeBlanks(String[] in) { - List<String> out = new ArrayList<String>(); - for (String s : in) { - if (!s.trim().isEmpty()) out.add(s); - } - return out.toArray(new String[0]); - } - - private void compare(String name, String expectedFile, String actualFile) { - String[] expectedLines = expectedFile.split("(\\r?\\n)"); - String[] actualLines = actualFile.split("(\\r?\\n)"); - if (actualLines[0].startsWith("// Generated by delombok at ")) { - actualLines[0] = ""; - } - expectedLines = removeBlanks(expectedLines); - actualLines = removeBlanks(actualLines); - int size = Math.min(expectedLines.length, actualLines.length); - for (int i = 0; i < size; i++) { - String expected = expectedLines[i]; - String actual = actualLines[i]; - if (!expected.equals(actual)) { - fail(String.format("Difference in line %s(%d):\nExpected `%s`\nGot `%s`\n", name, i, expected, actual)); - } - } - if (expectedLines.length > actualLines.length) { - fail(String.format("Missing line %s(%d): %s\n", name, size, expectedLines[size])); - } - if (expectedLines.length < actualLines.length) { - fail(String.format("Extra line %s(%d): %s\n", name, size, actualLines[size])); - } - } - - private String readAfter(File file) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File(AFTER_FOLDER, file.getName()))); - StringBuilder result = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - result.append(line); - result.append(LINE_SEPARATOR); - } - reader.close(); - return result.toString(); + TestViaDelombok.runComparison(BEFORE_DIR, AFTER_DIR); } } |