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

    transformer.add(closure);

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

    transformer.add(closure);

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

    transformer.add(closure);

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

    transformer.add(closure);

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

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original transformed"));
  }
  @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"));
  }
 @Test
 public void doesNothingWhenNoTransformersAdded() {
   assertThat(transformer.transform("value"), equalTo("value"));
 }