Пример #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"));
 }