コード例 #1
0
  /** Test compilation success. */
  @Test
  public void testCompilationSuccess() {
    JavaDynamicCompiler compiler = new JavaDynamicCompiler();
    compiler.init();
    JavaDynamicBean dummySource = new JavaDynamicBean("dummyClass", "class dummyClass {}");

    Collection<JavaDynamicBean> compiledClasses = compiler.compile(Arrays.asList(dummySource));
    Assert.assertEquals(compiledClasses.size(), 1);
    JavaDynamicBean compiledClass = compiledClasses.iterator().next();
    Assert.assertEquals(compiledClass.getName(), "dummyClass");
    Assert.assertNotNull(compiledClass.getBytes());
  }
コード例 #2
0
  /** Test compilation failure. */
  @Test
  public void testCompilationFailure() {
    JavaDynamicCompiler compiler = new JavaDynamicCompiler();
    compiler.init();
    JavaDynamicBean dummySource = new JavaDynamicBean("dummyClass", "dummyClass {}");

    JavaDynamicException expectedException = null;
    try {
      compiler.compile(Arrays.asList(dummySource));
    } catch (JavaDynamicException e) {
      expectedException = e;
    }
    Assert.assertNotNull(expectedException);
    Assert.assertFalse(strIsEmpty(expectedException.toString()));
  }