public void assertCompilesTo(CharSequence source, final File expectedResult) throws IOException { if(expectedResult.canRead()){ String expectedCompilationResult = Resources.toString(expectedResult.toURI().toURL(), Charsets.UTF_8); assertCompilesTo(source, expectedCompilationResult); } else{ final boolean[] called = {false}; compile(source, new IAcceptor<CompilationTestHelper.Result>() { public void accept(Result r) { writeResultToFile(r, expectedResult); called[0] = true; } }); Assert.assertTrue("Nothing was generated but the expectation was :\n"+expectedResult, called[0]); } }
@Test public void testGeneratedValidJavaCode() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("entity MyEntity {"); _builder.newLine(); _builder.append("\t"); _builder.append("string myAttribute;"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(final CompilationTestHelper.Result it) { it.getCompiledClass(); } }; this._compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testValidGeneratedJavaCode() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("entity MyEntity {"); _builder.newLine(); _builder.append("\t"); _builder.append("attr e = new MyEntity;"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(final CompilationTestHelper.Result it) { it.getCompiledClass(); } }; this._compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
public void assertCompilesTo(CharSequence source, final CharSequence expected) throws IOException { final boolean[] called = {false}; compile(source, new IAcceptor<CompilationTestHelper.Result>() { public void accept(Result r) { String actual = stringOf(r); Assert.assertEquals(removeEndWhiteSpace(expected), removeEndWhiteSpace(actual)); called[0] = true; } public String removeEndWhiteSpace(final CharSequence text) { return text.toString().trim().replaceAll("[ \t]+(\r?\n)", "$1"); } }); Assert.assertTrue("Nothing was generated but the expectation was :\n"+expected, called[0]); }
@Test public void testTwoCompiledClasses() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("entity FirstEntity {"); _builder.newLine(); _builder.append("\t"); _builder.append("SecondEntity myAttribute;"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append("entity SecondEntity {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(final CompilationTestHelper.Result it) { Class<?> _compiledClass = it.getCompiledClass("entities.FirstEntity"); Assert.assertNotNull(_compiledClass); Class<?> _compiledClass_1 = it.getCompiledClass("entities.SecondEntity"); Assert.assertNotNull(_compiledClass_1); } }; this._compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }