File tree Expand file tree Collapse file tree
src/test/java/org/mdkt/compiler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .mdkt .compiler ;
22
3+ import java .util .List ;
34import java .util .Map ;
45
56import 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}
You can’t perform that action at this time.
0 commit comments