コード例 #1
0
  @Test
  public void originalObjectIsSetAsDelegateForClosure() {
    Closure closure = HelperUtil.toClosure("{ substring(1, 3) }");

    transformer.add(closure);

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

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("[original]"));
  }
コード例 #3
0
  @Test
  public void usesOriginalObjectWhenClosureReturnsObjectOfUnexpectedType() {
    Closure closure = HelperUtil.toClosure("{ 9 }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original"));
  }
コード例 #4
0
  @Test
  public void usesOriginalObjectWhenClosureReturnsNull() {
    Closure closure = HelperUtil.toClosure("{ null }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original"));
  }
コード例 #5
0
  @Test
  public void canUseAClosureAsATransformer() {
    Closure closure = HelperUtil.toClosure("{ it + ' transformed' }");

    transformer.add(closure);

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