[tests] adds Groovy cases to not-null instrumenter test

This commit is contained in:
Roman Shevchenko
2018-10-08 18:55:05 +02:00
parent bed035b0ad
commit bff1c28f85
3 changed files with 51 additions and 3 deletions
@@ -0,0 +1,9 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import org.jetbrains.annotations.NotNull
@SuppressWarnings("unused")
enum GroovyEnum {
Value(null, "1");
GroovyEnum(String s1, @NotNull String s2) { }
}
@@ -0,0 +1,12 @@
import org.jetbrains.annotations.NotNull
@SuppressWarnings("unused")
class GroovyInnerClass {
GroovyInnerClass() {
new Inner(null, "")
}
private class Inner {
Inner(String s1, @NotNull String s2) { }
}
}
@@ -19,6 +19,7 @@ import org.junit.Test;
import org.junit.rules.TestName;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -144,6 +145,12 @@ public class NotNullVerifyingInstrumenterTest {
assertNotNull(testClass.getField("Value").get(null));
}
@Test
public void testGroovyEnum() throws Exception {
Class testClass = prepareTest();
assertNotNull(testClass.getField("Value").get(null));
}
@Test
public void testStaticInnerClass() throws Exception {
Class aClass = prepareTest();
@@ -156,6 +163,12 @@ public class NotNullVerifyingInstrumenterTest {
assertNotNull(aClass.newInstance());
}
@Test
public void testGroovyInnerClass() throws Exception {
Class aClass = prepareTest();
assertNotNull(aClass.newInstance());
}
@Test
public void testSkipBridgeMethods() throws Exception {
Class<?> testClass = prepareTest();
@@ -277,15 +290,29 @@ public class NotNullVerifyingInstrumenterTest {
List<String> cmdLine = ContainerUtil.newArrayList("-d", classesDir.getAbsolutePath(), "-classpath", testDir + "/annotations.jar");
if (withDebugInfo) cmdLine.add("-g");
cmdLine.add(testDir + '/' + testName + ".java");
com.sun.tools.javac.Main.compile(ArrayUtil.toStringArray(cmdLine));
Class mainClass = null;
File testFile = new File(testDir, testName + ".java");
if (testFile.exists()) {
cmdLine.add(testFile.getPath());
com.sun.tools.javac.Main.compile(ArrayUtil.toStringArray(cmdLine));
}
else {
testFile = new File(testDir, testName + ".groovy");
if (testFile.exists()) {
cmdLine.add(testFile.getPath());
org.codehaus.groovy.tools.FileSystemCompiler.main(ArrayUtil.toStringArray(cmdLine));
}
else {
throw new FileNotFoundException("No test source for " + testName);
}
}
File[] files = classesDir.listFiles();
assertNotNull(files);
Arrays.sort(files, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
boolean modified = false;
MyClassLoader classLoader = new MyClassLoader(getClass().getClassLoader());
Class mainClass = null;
for (File file: files) {
FailSafeClassReader reader = new FailSafeClassReader(FileUtil.loadFileBytes(file));
ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);