Exemplo n.º 1
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());
  }
Exemplo n.º 2
0
  /** Test object equality. */
  @Test(timeout = 1000)
  public void testEquality() {
    JSFunctionBody firstFunctionBody = JSFunctionBody.factory.create("nop();");
    JSFunctionBody secondFunctionBody = JSFunctionBody.factory.create("foobar();");

    // Unequality
    assertFalse(
        "Function bodies with different code must not be equal.",
        firstFunctionBody.equals(secondFunctionBody));

    // Equality
    secondFunctionBody.setCode("nop();");
    assertTrue("Function bodies must be equal.", firstFunctionBody.equals(secondFunctionBody));

    assertTrue(
        "Function body must be equal to itself.", firstFunctionBody.equals(firstFunctionBody));
  }
Exemplo n.º 3
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);
  }