Exemple #1
0
  /** Test code handling. */
  @Test(timeout = 1000)
  public void testCodeHandling() {
    JSFunctionBody functionBody = JSFunctionBody.factory.create("Alpha", "Beta", "Gamma", "Delta");
    assertEquals(
        "Output must equal expected form.", "Alpha\nBeta\nGamma\nDelta", functionBody.toString());
    System.out.println(functionBody);

    functionBody.appendCode("Omega");
    assertEquals(
        "Output must equal expected form.",
        "Alpha\nBeta\nGamma\nDelta\nOmega",
        functionBody.toString());
    System.out.println(functionBody);

    functionBody.setCode("Foobar");
    assertEquals("Output must equal expected form.", "Foobar", functionBody.toString());
    System.out.println(functionBody);

    functionBody.clearCode();
    assertEquals("Output must equal expected form.", "", functionBody.toString());
    System.out.println(functionBody);

    functionBody.setCode("Beta");
    functionBody.prependCode("Alpha");
    functionBody.appendCode("Gamma", "Delta");
    assertEquals(
        "Output must equal expected form.", "Alpha\nBeta\nGamma\nDelta", functionBody.toString());
    System.out.println(functionBody);
  }
Exemple #2
0
  /** Test object creation with factory. */
  @Test(timeout = 1000)
  public void testFactory() {
    JSFunctionBody functionBody = JSFunctionBody.factory.create();
    assertNotNull("JSFunctionBody object must not be null.", functionBody);
    assertEquals("Source code must be empty.", "", functionBody.toString());

    functionBody = JSFunctionBody.factory.create("foobar");
    assertNotNull("JSFunctionBody object must not be null.", functionBody);
    assertEquals("Source code must match initial value.", "foobar", functionBody.toString());
  }