Ejemplo n.º 1
0
  @Test
  public void originalObjectIsSetAsDelegateForClosure() {
    Closure closure = HelperUtil.toClosure("{ substring(1, 3) }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("ri"));
  }
Ejemplo n.º 2
0
  @Test
  public void closureCanTransformAStringIntoAGString() {
    Closure closure = HelperUtil.toClosure("{ \"[$it]\" }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("[original]"));
  }
Ejemplo n.º 3
0
  @Test
  public void usesOriginalObjectWhenClosureReturnsObjectOfUnexpectedType() {
    Closure closure = HelperUtil.toClosure("{ 9 }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original"));
  }
Ejemplo n.º 4
0
  @Test
  public void usesOriginalObjectWhenClosureReturnsNull() {
    Closure closure = HelperUtil.toClosure("{ null }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original"));
  }
Ejemplo n.º 5
0
  @Test
  public void canUseAClosureAsATransformer() {
    Closure closure = HelperUtil.toClosure("{ it + ' transformed' }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original transformed"));
  }
Ejemplo n.º 6
0
  @Test
  public void passesObjectToEachTransformerInTurn() {
    @SuppressWarnings("unchecked")
    final Transformer<String> transformerA = context.mock(Transformer.class, "transformerA");
    @SuppressWarnings("unchecked")
    final Transformer<String> transformerB = context.mock(Transformer.class, "transformerB");

    context.checking(
        new Expectations() {
          {
            one(transformerA).transform("original");
            will(returnValue("a"));

            one(transformerB).transform("a");
            will(returnValue("b"));
          }
        });

    transformer.add(transformerA);
    transformer.add(transformerB);

    assertThat(transformer.transform("original"), equalTo("b"));
  }
Ejemplo n.º 7
0
 @Test
 public void doesNothingWhenNoTransformersAdded() {
   assertThat(transformer.transform("value"), equalTo("value"));
 }