Example usage for org.apache.commons.collections15 Closure execute

List of usage examples for org.apache.commons.collections15 Closure execute

Introduction

In this page you can find the example usage for org.apache.commons.collections15 Closure execute.

Prototype

public void execute(T input);

Source Link

Document

Performs an action on the specified input object.

Usage

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testClosureFor_AssignToClosureWithMatchingSourceType() {
    Grows grows = new Grows();

    Closure<Grows> superTypeRet = closureFor(CALLS_TO_GROWS.incAndReturn()); // happy path
    assertEquals(0, grows.i);/*from w  ww .j a v  a 2s  . c o  m*/

    superTypeRet.execute(grows);
    assertEquals(1, grows.i);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testClosureFor_AssignToClosureWithSourceSuperType() {
    Grows grows = new Grows();

    Closure<Object> superTypeRet = closureFor(CALLS_TO_GROWS.incAndReturn()); // Generic type is Object instead of Grows
    assertEquals(0, grows.i);/*from   ww w .  j  av  a  2 s .  c om*/

    superTypeRet.execute(grows);
    assertEquals(1, grows.i);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testClosureFor_AllowUpcastToExtensionGenericType() {
    Closure<Generic<? extends Object>> incClosure = closureFor(callsTo(Generic.class).incAndGet());
    Generic<Integer> integerGeneric = new Generic<Integer>(0);
    assertEquals(0, integerGeneric.number, 0.01);

    incClosure.execute(integerGeneric);

    assertEquals(1.0, integerGeneric.number, 0.01);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testClosureFor_TypedAndUntypedModes() {
    Closure<Grows> closure = closureFor(CALLS_TO_GROWS.incAndReturn(), safeNav());
    // Without safeNav() untyped Mode, this results in a NPE
    closure.execute(null);

    closure = closureFor(CALLS_TO_GROWS.incAndReturn(), safeNav((Void) null));
    // Without safeNav() TypedMode, this results in a NPE
    closure.execute(null);// w  w  w.j  a v a2s . c o  m
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testVoidClosure_withPrepare() {
    Grows grows = new Grows();

    prepareVoid(CALLS_TO_GROWS).inc();//www  .  ja v a  2  s .  co m
    Closure<Grows> normalCall = voidClosure();

    assertEquals(0, grows.i);
    normalCall.execute(grows);
    assertEquals(1, grows.i);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testVoidClosure_withoutPrepare() {
    Grows grows = new Grows();

    // non-preferred.  Better to use prepare() to help explain
    CALLS_TO_GROWS.inc();//  w  w  w .  j  a  v a  2  s.  co m
    Closure<Grows> normalCall = voidClosure();

    assertEquals(0, grows.i);
    normalCall.execute(grows);
    assertEquals(1, grows.i);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testVoidClosure_AssignToClosureWithSourceSuperTypeOk() {
    Grows grows = new Grows();

    prepareVoid(CALLS_TO_GROWS).inc();//from w ww.  j  av  a  2s.  c o m
    Closure<Object> superTypeRet = voidClosure(); // Generic type is Object instead of Grows
    assertEquals(0, grows.i);

    superTypeRet.execute(grows);
    assertEquals(1, grows.i);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testVoidClosure_unsafeAssignment() {
    prepareVoid(CALLS_TO_GROWS).inc();/*from w w w .  ja  v a 2 s . co  m*/
    Closure<Integer> unsafe = voidClosure(); // unsafe assignment compiles

    thrown.expect(FuncitoException.class);
    thrown.expectMessage("Method inc() does not exist");
    unsafe.execute(3); // invocation target type does not match prepared target type
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testVoidClosure_preparedForNonVoidMethodIsOk() {
    Grows grows = new Grows();
    assertEquals(0, grows.i);/*from   w w w .j a  va 2s . c o m*/

    prepareVoid(CALLS_TO_GROWS).incAndReturn();
    Closure<Grows> e = voidClosure();

    e.execute(grows);

    assertEquals(1, grows.i);
}

From source file:org.funcito.FuncitoCollectGenClosure_UT.java

@Test
public void testVoidClosure_TypedAndUntypedModes() {
    prepareVoid(CALLS_TO_GROWS).incAndReturn();
    Closure<Grows> closure = voidClosure(safeNav());
    // Without safeNav() untyped Mode, this results in a NPE
    closure.execute(null);

    prepareVoid(CALLS_TO_GROWS).incAndReturn();
    closure = voidClosure(safeNav((Void) null));
    // Without safeNav() TypedMode, this results in a NPE
    closure.execute(null);/*from  w  w  w. ja  va  2 s.  co  m*/
}