Skip to content

Commit 0543084

Browse files
committed
Added support for compiler options
Added ignore compiler warning
1 parent a6bfc19 commit 0543084

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/test/java/org/mdkt/compiler/InMemoryJavaCompilerTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.mdkt.compiler;
22

3+
import java.util.List;
34
import java.util.Map;
45

56
import org.junit.Assert;
@@ -67,4 +68,27 @@ public void compile_whenError() throws Exception {
6768
sourceCode.append("}");
6869
InMemoryJavaCompiler.newInstance().compile("org.mdkt.HelloClass", sourceCode.toString());
6970
}
71+
72+
@Test public void compile_FailOnWarnings() throws Exception{
73+
thrown.expect(CompilationException.class);
74+
StringBuffer sourceCode = new StringBuffer();
75+
76+
sourceCode.append("package org.mdkt;\n");
77+
sourceCode.append("public class HelloClass {\n");
78+
sourceCode.append(" public java.util.List<String> hello() { return new java.util.ArrayList(); }");
79+
sourceCode.append("}");
80+
InMemoryJavaCompiler.newInstance().compile("org.mdkt.HelloClass", sourceCode.toString());
81+
}
82+
83+
@Test public void compile_CompileAndIgnoreWarnings() throws Exception{
84+
StringBuffer sourceCode = new StringBuffer();
85+
86+
sourceCode.append("package org.mdkt;\n");
87+
sourceCode.append("public class HelloClass {\n");
88+
sourceCode.append(" public java.util.List<String> hello() { return new java.util.ArrayList(); }");
89+
sourceCode.append("}");
90+
Class<?> helloClass = InMemoryJavaCompiler.newInstance().useIgnoreWarnings().compile("org.mdkt.HelloClass", sourceCode.toString());
91+
List<?> res = (List) helloClass.getMethod("hello").invoke(helloClass.newInstance());
92+
Assert.assertEquals(0, res.size());
93+
}
7094
}

0 commit comments

Comments
 (0)