diff --git a/test/org/jetbrains/java/decompiler/DecompilerTestFixture.java b/test/org/jetbrains/java/decompiler/DecompilerTestFixture.java index b3385e2..58f6db0 100644 --- a/test/org/jetbrains/java/decompiler/DecompilerTestFixture.java +++ b/test/org/jetbrains/java/decompiler/DecompilerTestFixture.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -104,13 +105,14 @@ public class DecompilerTestFixture { public static void assertFilesEqual(File expected, File actual) { if (expected.isDirectory()) { - assertThat(actual.list(), Matchers.arrayContainingInAnyOrder(expected.list())); - for (String name : expected.list()) { + String[] children = Objects.requireNonNull(expected.list()); + assertThat(actual.list(), Matchers.arrayContainingInAnyOrder(children)); + for (String name : children) { assertFilesEqual(new File(expected, name), new File(actual, name)); } } else { - assertThat(getContent(actual), Matchers.equalTo(getContent(expected))); + assertEquals(getContent(expected), getContent(actual)); } } diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index cbbbc2d..e905fb3 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -46,6 +46,7 @@ public class SingleClassesTest { } @Test public void testClassFields() { doTest("pkg/TestClassFields"); } + @Test public void testInterfaceFields() { doTest("pkg/TestInterfaceFields"); } @Test public void testClassLambda() { doTest("pkg/TestClassLambda"); } @Test public void testClassLoop() { doTest("pkg/TestClassLoop"); } @Test public void testClassSwitch() { doTest("pkg/TestClassSwitch"); } @@ -83,9 +84,6 @@ public class SingleClassesTest { @Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); } @Test public void testMemberAnnotations() { doTest("pkg/TestMemberAnnotations"); } @Test public void testStaticNameClash() { doTest("pkg/TestStaticNameClash"); } - @Test public void testInterfaceWithPrimitiveField() { doTest("pkg/TestInterfaceWithPrimitiveField"); } - @Test public void testInterfaceWithObjectField() { doTest("pkg/TestInterfaceWithObjectField"); } - @Test public void testTestMutableStaticOtherClass() { doTest("pkg/TestMutableStaticOtherClass"); } protected void doTest(String testFile, String... companionFiles) { ConsoleDecompiler decompiler = fixture.getDecompiler(); @@ -110,7 +108,7 @@ public class SingleClassesTest { File decompiledFile = new File(fixture.getTargetDir(), testName + ".java"); assertTrue(decompiledFile.isFile()); File referenceFile = new File(fixture.getTestDataDir(), "results/" + testName + ".dec"); - assertTrue("Expecting " + referenceFile.getAbsolutePath() + " to be a file", referenceFile.isFile()); + assertTrue(referenceFile.isFile()); assertFilesEqual(referenceFile, decompiledFile); } @@ -132,4 +130,4 @@ public class SingleClassesTest { return files; } -} +} \ No newline at end of file diff --git a/testData/classes/pkg/TestClassFields$Inner.class b/testData/classes/pkg/TestClassFields$Inner.class new file mode 100644 index 0000000..1c16a7e Binary files /dev/null and b/testData/classes/pkg/TestClassFields$Inner.class differ diff --git a/testData/classes/pkg/TestClassFields.class b/testData/classes/pkg/TestClassFields.class index a25091d..e8788e0 100644 Binary files a/testData/classes/pkg/TestClassFields.class and b/testData/classes/pkg/TestClassFields.class differ diff --git a/testData/classes/pkg/TestInterfaceFields.class b/testData/classes/pkg/TestInterfaceFields.class new file mode 100644 index 0000000..4f39e33 Binary files /dev/null and b/testData/classes/pkg/TestInterfaceFields.class differ diff --git a/testData/classes/pkg/TestInterfaceWithObjectField.class b/testData/classes/pkg/TestInterfaceWithObjectField.class deleted file mode 100644 index bf7ec68..0000000 Binary files a/testData/classes/pkg/TestInterfaceWithObjectField.class and /dev/null differ diff --git a/testData/classes/pkg/TestInterfaceWithPrimitiveField.class b/testData/classes/pkg/TestInterfaceWithPrimitiveField.class deleted file mode 100644 index b079f95..0000000 Binary files a/testData/classes/pkg/TestInterfaceWithPrimitiveField.class and /dev/null differ diff --git a/testData/classes/pkg/TestMutableStaticOtherClass.class b/testData/classes/pkg/TestMutableStaticOtherClass.class deleted file mode 100644 index 14b1efd..0000000 Binary files a/testData/classes/pkg/TestMutableStaticOtherClass.class and /dev/null differ diff --git a/testData/results/TestClassFields.dec b/testData/results/TestClassFields.dec index d139051..6917171 100644 --- a/testData/results/TestClassFields.dec +++ b/testData/results/TestClassFields.dec @@ -1,26 +1,37 @@ package pkg; public class TestClassFields { - static int staticMutable; private static int[] sizes; private static String[] names = new String[]{"name1", "name2"}; + private static final int SIZE; static { - sizes = new int[names.length];// 27 - }// 28 + sizes = new int[names.length];// 15 + TestClassFields.Inner.staticMutable = 3;// 17 + SIZE = TestClassFields.Inner.staticMutable;// 14 18 + }// 19 + + private static class Inner { + private static int staticMutable; + } } class 'pkg/TestClassFields' { method ' ()V' { + 0 10 + 2 9 11 8 14 8 17 8 1a 9 + 22 10 + 25 11 } } Lines mapping: -27 <-> 9 -28 <-> 10 -Not mapped: -26 +14 <-> 11 +15 <-> 9 +17 <-> 10 +18 <-> 11 +19 <-> 12 diff --git a/testData/results/TestInterfaceFields.dec b/testData/results/TestInterfaceFields.dec new file mode 100644 index 0000000..d08e2fe --- /dev/null +++ b/testData/results/TestInterfaceFields.dec @@ -0,0 +1,9 @@ +package pkg; + +import java.math.BigDecimal; + +public interface TestInterfaceFields { + BigDecimal BIG_ZERO = BigDecimal.ZERO; + int MAX_BYTE_VALUE = 127; +} + diff --git a/testData/results/TestInterfaceWithObjectField.dec b/testData/results/TestInterfaceWithObjectField.dec deleted file mode 100644 index c9418d8..0000000 --- a/testData/results/TestInterfaceWithObjectField.dec +++ /dev/null @@ -1,8 +0,0 @@ -package pkg; - -import java.math.BigDecimal; - -public interface TestInterfaceWithObjectField { - BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO; -} - diff --git a/testData/results/TestInterfaceWithPrimitiveField.dec b/testData/results/TestInterfaceWithPrimitiveField.dec deleted file mode 100644 index 542e858..0000000 --- a/testData/results/TestInterfaceWithPrimitiveField.dec +++ /dev/null @@ -1,6 +0,0 @@ -package pkg; - -public interface TestInterfaceWithPrimitiveField { - int MAX_BYTE_VALUE = 127; -} - diff --git a/testData/results/TestMutableStaticOtherClass.dec b/testData/results/TestMutableStaticOtherClass.dec deleted file mode 100644 index 6e7ed33..0000000 --- a/testData/results/TestMutableStaticOtherClass.dec +++ /dev/null @@ -1,27 +0,0 @@ -package pkg; - -import pkg.TestClassFields; - -public class TestMutableStaticOtherClass { - private static final int SIZE; - - static { - TestClassFields.staticMutable = 3;// 12 - SIZE = TestClassFields.staticMutable;// 13 - }// 14 -} - -class 'pkg/TestMutableStaticOtherClass' { - method ' ()V' { - 0 8 - 1 8 - 4 9 - 7 9 - a 10 - } -} - -Lines mapping: -12 <-> 9 -13 <-> 10 -14 <-> 11 diff --git a/testData/src/pkg/TestClassFields.java b/testData/src/pkg/TestClassFields.java index 2341ff7..8a77fe0 100644 --- a/testData/src/pkg/TestClassFields.java +++ b/testData/src/pkg/TestClassFields.java @@ -1,29 +1,20 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package pkg; public class TestClassFields { + private static class Inner { + private static int staticMutable; + } - static int staticMutable; private static int[] sizes; private static String[] names; - static { + private static final int SIZE; + static { names = new String[]{"name1", "name2"}; sizes = new int[names.length]; + + Inner.staticMutable = 3; + SIZE = Inner.staticMutable; } -} +} \ No newline at end of file diff --git a/testData/src/pkg/TestInterfaceFields.java b/testData/src/pkg/TestInterfaceFields.java new file mode 100644 index 0000000..e117258 --- /dev/null +++ b/testData/src/pkg/TestInterfaceFields.java @@ -0,0 +1,8 @@ +package pkg; + +import java.math.BigDecimal; + +public interface TestInterfaceFields { + BigDecimal BIG_ZERO = BigDecimal.ZERO; + int MAX_BYTE_VALUE = Byte.MAX_VALUE; +} \ No newline at end of file diff --git a/testData/src/pkg/TestInterfaceWithObjectField.java b/testData/src/pkg/TestInterfaceWithObjectField.java deleted file mode 100644 index ac0bd64..0000000 --- a/testData/src/pkg/TestInterfaceWithObjectField.java +++ /dev/null @@ -1,13 +0,0 @@ -package pkg; - -import java.math.BigDecimal; - -/** - * @author Alexandru-Constantin Bledea - * @since March 06, 2016 - */ -public interface TestInterfaceWithObjectField { - - BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO; - -} diff --git a/testData/src/pkg/TestInterfaceWithPrimitiveField.java b/testData/src/pkg/TestInterfaceWithPrimitiveField.java deleted file mode 100644 index 89d1b7a..0000000 --- a/testData/src/pkg/TestInterfaceWithPrimitiveField.java +++ /dev/null @@ -1,13 +0,0 @@ -package pkg; - -import java.math.BigDecimal; - -/** - * @author Alexandru-Constantin Bledea - * @since March 06, 2016 - */ -public interface TestInterfaceWithPrimitiveField { - - int MAX_BYTE_VALUE = Byte.MAX_VALUE; - -} diff --git a/testData/src/pkg/TestMutableStaticOtherClass.java b/testData/src/pkg/TestMutableStaticOtherClass.java deleted file mode 100644 index 4015c83..0000000 --- a/testData/src/pkg/TestMutableStaticOtherClass.java +++ /dev/null @@ -1,15 +0,0 @@ -package pkg; - -/** - * @author Alexandru-Constantin Bledea - * @since March 17, 2016 - */ -public class TestMutableStaticOtherClass { - - private static final int SIZE; - - static { - TestClassFields.staticMutable = 3; - SIZE = TestClassFields.staticMutable; - } -}