public static void assertFail(String name, String... expectedMessage) throws Exception { CompilerAssert<File, File> compiler = compiler(name); compiler.formalErrorReporting(); List<CompilationError> errors = compiler.failCompile(); assertEquals(1, errors.size()); assertEquals(AssetMetaModelPlugin.CANNOT_PROCESS_ASSET, errors.get(0).getCode()); assertEquals(Arrays.asList(expectedMessage), errors.get(0).getArguments()); } }
@Test public void testBundleNotFound() throws Exception { CompilerAssert<File, File> compilerAssert = compiler("examples.app2"); compilerAssert.formalErrorReporting(); //<1> List<CompilationError> errors = compilerAssert.failCompile(); //<2> assertEquals(1, errors.size()); //<3> CompilationError error = errors.get(0); assertEquals(BundleGenMetaModelPlugin.BUNDLE_NOT_FOUND, error.getCode()); //<4> assertEquals(Collections.singletonList("mybundle"), error.getArguments()); File source = error.getSourceFile(); assertEquals("package-info.java", source.getName()); assertEquals("app2", source.getParentFile().getName()); } // end::testBundleNotFound[]
appendable.append("<p>").append(error.getMessage()).append("</p>"); File source = error.getSourceFile(); if (source != null) { int line = error.getLocation().getLine(); int from = line - 2; int to = line + 3;
@Test public void testNotFound() throws Exception { List<CompilationError> errors = compiler("plugin.template.tag.notfound").formalErrorReporting(true).failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertTrue(error.getSource().endsWith("template/tag/notfound/A.java")); assertEquals(TemplateMetaModel.UNKNOWN_TAG, error.getCode()); assertEquals(Arrays.asList("notfound"), error.getArguments()); }
@Test public void testAbstractClass() throws Exception { CompilerAssert<File, File> compiler = compiler("plugin.binding.implementation.abstractclass"); compiler.formalErrorReporting(true); List<CompilationError> errors = compiler.failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(BindingMetaModelPlugin.IMPLEMENTATION_NOT_ABSTRACT, error.getCode()); File f = compiler.getSourcePath().getPath("plugin", "binding", "implementation", "abstractclass", "package-info.java"); assertEquals(f, error.getSourceFile()); }
assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(null, error.getCode()); assertEquals(Collections.<String>emptyList(), error.getArguments()); assertEquals(null, error.getSource()); assertTrue(error.getMessage().contains("the_message")); assertNull(error.getSourceFile()); assertNull(error.getLocation());
@Test public void testAbstract() throws Exception { List<CompilationError> app = compiler("plugin.controller.abstract_").formalErrorReporting().failCompile(); assertEquals(1, app.size()); CompilationError error = app.get(0); assertEquals(ControllerMetaModel.CONTROLLER_IS_ABSTRACT, error.getCode()); assertTrue("Was expecting source to end with abstract_/A.java", error.getSource().endsWith("abstract_/A.java")); }
@Test public void testCompile() throws Exception { CompilerAssert<?, ?> app = compiler("plugin.asset.notfound.compile"); app.formalErrorReporting(); List<CompilationError> errors = app.failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(AssetMetaModelPlugin.ASSET_NOT_FOUND, error.getCode()); }
public void testInvalidMethodName() throws Exception { CompilerAssert<?, ?> compiler = compiler("plugin.template.url.invalid_method_name"); List<CompilationError> errors = compiler.failCompile(); assertEquals("Was expecting 1 error instead of " + errors, 1, errors.size()); CompilationError error = errors.get(0); assertEquals("/plugin/template/url/invalid_method_name/A.java", error.getSource()); }
@Test public void testNotAssignable() throws Exception { CompilerAssert<File, File> compiler = compiler("plugin.binding.provider.notassignable"); compiler.formalErrorReporting(true); List<CompilationError> errors = compiler.failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(BindingMetaModelPlugin.PROVIDER_NOT_ASSIGNABLE, error.getCode()); File f = compiler.getSourcePath().getPath("plugin", "binding", "provider", "notassignable", "package-info.java"); assertEquals(f, error.getSourceFile()); }
assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(null, error.getCode()); assertEquals(Collections.<String>emptyList(), error.getArguments()); assertEquals(null, error.getSource()); assertTrue(error.getMessage().contains("the_message")); assertNull(error.getSourceFile()); assertNull(error.getLocation());
@Test public void testAbstract() throws Exception { List<CompilationError> app = compiler("plugin.controller.abstract_").formalErrorReporting().failCompile(); assertEquals(1, app.size()); CompilationError error = app.get(0); assertEquals(ControllerMetaModel.CONTROLLER_IS_ABSTRACT, error.getCode()); assertTrue("Was expecting source to end with abstract_/A.java", error.getSource().endsWith("abstract_/A.java")); }
@Test public void testNotFound() throws Exception { List<CompilationError> errors = compiler("plugin.template.tag.notfound").formalErrorReporting(true).failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertTrue(error.getSource().endsWith("template/tag/notfound/A.java")); assertEquals(TemplateMetaModel.UNKNOWN_TAG, error.getCode()); assertEquals(Arrays.asList("notfound"), error.getArguments()); }
@Test public void testCompile() throws Exception { CompilerAssert<?, ?> app = compiler("plugin.asset.notfound.compile"); app.formalErrorReporting(); List<CompilationError> errors = app.failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(AssetMetaModelPlugin.ASSET_NOT_FOUND, error.getCode()); }
public void testInvalidMethodArgs() throws Exception { CompilerAssert<?, ?> compiler = compiler("plugin.template.url.invalid_method_args"); List<CompilationError> errors = compiler.failCompile(); assertEquals("Was expecting 1 error instead of " + errors, 1, errors.size()); CompilationError error = errors.get(0); assertEquals("/plugin/template/url/invalid_method_args/A.java", error.getSource()); }
@Test public void testAbstractClass() throws Exception { CompilerAssert<File, File> compiler = compiler("plugin.binding.provider.abstractclass"); compiler.formalErrorReporting(true); List<CompilationError> errors = compiler.failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(BindingMetaModelPlugin.IMPLEMENTATION_NOT_ABSTRACT, error.getCode()); File f = compiler.getSourcePath().getPath("plugin", "binding", "provider", "abstractclass", "package-info.java"); assertEquals(f, error.getSourceFile()); }
assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(null, error.getCode()); assertEquals(Collections.<String>emptyList(), error.getArguments()); assertEquals(fs.getPath("compiler", "annotationexception", "A.java"), error.getSourceFile()); assertTrue(error.getMessage().contains("the_message")); assertNotNull(error.getSourceFile()); assertNotNull(error.getLocation()); String absolutePath = error.getSourceFile().getAbsolutePath(); char separator = File.separatorChar; String[] absoluteNames = Tools.split(absolutePath, separator);
public static void assertFail(String name, String... expectedMessage) throws Exception { CompilerAssert<File, File> compiler = compiler(name); compiler.formalErrorReporting(); List<CompilationError> errors = compiler.failCompile(); assertEquals(1, errors.size()); assertEquals(AssetMetaModelPlugin.CANNOT_PROCESS_ASSET, errors.get(0).getCode()); assertEquals(Arrays.asList(expectedMessage), errors.get(0).getArguments()); } }
appendable.append("<p>").append(error.getMessage()).append("</p>"); File source = error.getSourceFile(); if (source != null) { int line = error.getLocation().getLine(); int from = line - 2; int to = line + 3;
@Test public void testMakeAbstract() throws Exception { CompilerAssert<File, File> helper = incrementalCompiler("metamodel.controller").formalErrorReporting(); helper.assertCompile(); // JavaFile file = helper.assertJavaSource("metamodel.controller.A"); ClassOrInterfaceDeclaration a = file.assertDeclaration(); a.setModifiers(a.getModifiers() | Modifier.ABSTRACT); file.assertSave(); List<CompilationError> errors = helper.failCompile(); CompilationError error = errors.get(0); assertEquals(ControllerMetaModel.CONTROLLER_IS_ABSTRACT, error.getCode()); assertTrue("Was expecting " + error.getSource() + " to end with A.java", error.getSource().endsWith("A.java")); } }