1111import com .helger .jcodemodel .writer .StringCodeWriter ;
1212
1313/**
14- * abstract method for a test of copying. Such a test consist in creating a source codemodel, copying it, check the
15- * equality of the representation of the copy and the source ; then apply several modifications on the source, each
16- * result in a model varying from the copy ; then apply those modifications to the copy, which in the end should have
17- * the same representation as the source.<br />
18- *
14+ * abstract method for a test of copying. Such a test consist in creating a source codemodel,
15+ * copying it, check the equality of the representation of the copy and the source ; then apply
16+ * several modifications on the source, each result in a model varying from the copy ; then apply
17+ * those modifications to the copy, which in the end should have the same representation as the
18+ * source.<br />
1919 * This class defines
2020 * <ul>
2121 * <li>{@link #execute()} that should be called in the test,</li>
2222 * <li>{@link #createCM()} that creates a base code model,</li>
2323 * <li>{@link #copy(JCodeModel)} that defines how to copy a {@link JCodeModel},</li>
2424 * <li>{@link #represent(JCodeModel)} to make a representation of a codemodel,</li>
25- * <li> {@link #modifications()} that lists a series of modifications to apply.</li>
25+ * <li>{@link #modifications()} that lists a series of modifications to apply.</li>
2626 * </ul>
2727 *
2828 * @author glelouet
@@ -33,15 +33,15 @@ public class ModelCopyTest
3333 @ Test
3434 public void execute ()
3535 {
36- JCodeModel cm = createCM ();
37- JCodeModel copy = copy (cm );
36+ final JCodeModel cm = createCM ();
37+ final JCodeModel copy = copy (cm );
3838 Assert .assertEquals (represent (cm ), represent (copy ));
39- for (Consumer <JCodeModel > m : modifications ())
39+ for (final Consumer <JCodeModel > m : modifications ())
4040 {
4141 m .accept (cm );
4242 Assert .assertNotEquals (represent (cm ), represent (copy ));
4343 }
44- for (Consumer <JCodeModel > m : modifications ())
44+ for (final Consumer <JCodeModel > m : modifications ())
4545 m .accept (copy );
4646 Assert .assertEquals (represent (cm ), represent (copy ));
4747 }
@@ -50,65 +50,62 @@ protected JCodeModel createCM ()
5050 {
5151 try
5252 {
53- JCodeModel ret = new JCodeModel ();
53+ final JCodeModel ret = new JCodeModel ();
5454
5555 // create an interface IMyClass with method default String string(){return "yes";}
56- JDefinedClass itf = ret ._class ("my.pckg.IMyClass" , EClassType .INTERFACE );
57- JMethod methd = itf .method (JMod .PUBLIC | JMod .DEFAULT , ret .ref (String .class ), "string" );
56+ final JDefinedClass itf = ret ._class ("my.pckg.IMyClass" , EClassType .INTERFACE );
57+ final JMethod methd = itf .method (JMod .PUBLIC | JMod .DEFAULT , ret .ref (String .class ), "string" );
5858 methd .body ()._return (JExpr .lit ("yes" ));
5959
6060 // create an implementation of that interface, for which toString() returns the string();
61- JDefinedClass imp = itf ._package ()._class (JMod .PUBLIC , "Impl" )._implements (itf );
61+ final JDefinedClass imp = itf ._package ()._class (JMod .PUBLIC , "Impl" )._implements (itf );
6262 imp .method (JMod .PUBLIC , ret .ref (String .class ), "toString" ).body ()._return (JExpr .invoke (methd ));
6363 return ret ;
6464 }
65- catch (JCodeModelException e )
65+ catch (final JCodeModelException e )
6666 {
67- throw new UnsupportedOperationException ("catch this" , e );
67+ throw new UnsupportedOperationException (e );
6868 }
6969 }
7070
71- protected JCodeModel copy (JCodeModel source )
71+ protected JCodeModel copy (final JCodeModel source )
7272 {
7373 return source .copy ();
7474 }
7575
76- protected String represent (JCodeModel target )
76+ protected String represent (final JCodeModel target )
7777 {
7878 return StringCodeWriter .represent (target );
7979 }
8080
8181 public Collection <Consumer <JCodeModel >> modifications ()
8282 {
83- return Arrays .asList (cm ->
84- {
83+ return Arrays .asList (cm -> {
8584 try
8685 {
8786 cm ._class (JMod .PUBLIC , "MyClass" );
8887 }
89- catch (JCodeModelException e )
88+ catch (final JCodeModelException e )
9089 {
91- throw new UnsupportedOperationException ("catch this" , e );
90+ throw new UnsupportedOperationException (e );
9291 }
93- }, cm ->
94- {
95- JDefinedClass cl = cm ._getClass ("my.pckg.IMyClass" );
92+ }, cm -> {
93+ final JDefinedClass cl = cm ._getClass ("my.pckg.IMyClass" );
9694 cl .method (JMod .DEFAULT , cm .BOOLEAN , "yes" ).body ()._return (JExpr .TRUE );
97- }, cm ->
98- {
95+ }, cm -> {
9996 try
10097 {
101- JDefinedClass cl = cm ._getClass ("my.pckg.IMyClass" );
102- JDefinedClass newcl = cl ._class (JMod .STATIC | JMod .PUBLIC , "InternalIntClass" );
103- JFieldVar fld = newcl .field (JMod .PRIVATE , cm .INT , "intField" );
104- JMethod cons = newcl .constructor (JMod .PUBLIC );
105- JVar consParam = cons .param (cm .INT , "number" );
98+ final JDefinedClass cl = cm ._getClass ("my.pckg.IMyClass" );
99+ final JDefinedClass newcl = cl ._class (JMod .STATIC | JMod .PUBLIC , "InternalIntClass" );
100+ final JFieldVar fld = newcl .field (JMod .PRIVATE , cm .INT , "intField" );
101+ final JMethod cons = newcl .constructor (JMod .PUBLIC );
102+ final JVar consParam = cons .param (cm .INT , "number" );
106103 cons .body ().assign (fld , consParam );
107104 newcl .method (JMod .PUBLIC , cm .INT , "incr" ).body ()._return (JExpr .preincr (fld ));
108105 }
109- catch (JCodeModelException e )
106+ catch (final JCodeModelException e )
110107 {
111- throw new UnsupportedOperationException ("catch this" , e );
108+ throw new UnsupportedOperationException (e );
112109 }
113110 });
114111 }
0 commit comments