Skip to content

Commit

Permalink
Added test for #56
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 25, 2017
1 parent 25debe0 commit fa1baa0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/java/com/helger/jcodemodel/JLambdaMethodRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,40 @@ public void testInstanceMethodRef_JMethod () throws JClassAlreadyExistsException
assertSame (aVar, aLambda.var ());
assertEquals ("myToString", aLambda.methodName ());
}

@Test
public void testInvocationMethodRef_Name () throws JClassAlreadyExistsException
{
final JCodeModel cm = new JCodeModel ();
final JDefinedClass cl = cm._class ("com.helger.test.LambdaInvocationMethodRefName");

final JLambdaMethodRef lambdaMethod = new JLambdaMethodRef (cm.ref ("test.Person"), "getFirstName");
final JInvocation jInvocation = JExpr._this ().invoke ("andThen").arg (lambdaMethod);
final JLambdaMethodRef aLambda = new JLambdaMethodRef (jInvocation, "apply");
assertEquals ("this.andThen(test.Person::getFirstName)::apply", CodeModelTestsHelper.toString (aLambda));

final JMethod con = cl.constructor (JMod.PUBLIC);
con.body ().decl (cm.ref (Object.class), "any", aLambda);
CodeModelTestsHelper.parseCodeModel (cm);
}

@Test
public void testInvocationMethodRef_JMethod () throws JClassAlreadyExistsException
{
final JCodeModel cm = new JCodeModel ();
final JDefinedClass cl = cm._class ("com.helger.test.LambdaInvocationMethodRefJMethod");

final JMethod m = cl.method (JMod.PUBLIC, cm.ref (String.class), "myToString");
final JVar p = m.param (Object.class, "obj");
m.body ()._return (cm.ref (String.class).staticInvoke ("valueOf").arg (p));

final JLambdaMethodRef lambdaMethod = new JLambdaMethodRef (cm.ref ("test.Person"), "getFirstName");
final JInvocation jInvocation = JExpr._this ().invoke ("andThen").arg (lambdaMethod);
final JLambdaMethodRef aLambda = new JLambdaMethodRef (jInvocation, m);
assertEquals ("this.andThen(test.Person::getFirstName)::myToString", CodeModelTestsHelper.toString (aLambda));

final JMethod con = cl.constructor (JMod.PUBLIC);
con.body ().decl (cm.ref (Object.class), "any", aLambda);
CodeModelTestsHelper.parseCodeModel (cm);
}
}

0 comments on commit fa1baa0

Please sign in to comment.