@@ -70,79 +70,50 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
7070 }
7171
7272 List <Expression > args = method .getArguments ();
73-
7473 Expression expected = args .get (0 );
7574 Expression actual = args .get (1 );
7675
76+ maybeAddImport ("org.assertj.core.api.Assertions" , "assertThat" );
77+ maybeRemoveImport (JUNIT_QUALIFIED_ASSERTIONS_CLASS_NAME );
78+
7779 if (args .size () == 2 ) {
78- method = method .withTemplate (
79- JavaTemplate .builder ("assertThat(#{anyArray()}).containsExactly(#{anyArray()});" )
80- .context (getCursor ())
81- .staticImports ("org.assertj.core.api.Assertions.assertThat" )
82- .javaParser (assertionsParser (ctx ))
83- .build (),
84- getCursor (),
85- method .getCoordinates ().replace (),
86- actual ,
87- expected
88- );
80+ return JavaTemplate .builder ("assertThat(#{anyArray()}).containsExactly(#{anyArray()});" )
81+ .staticImports ("org.assertj.core.api.Assertions.assertThat" )
82+ .javaParser (assertionsParser (ctx ))
83+ .build ()
84+ .apply (getCursor (), method .getCoordinates ().replace (), actual , expected );
8985 } else if (args .size () == 3 && !isFloatingPointType (args .get (2 ))) {
9086 Expression message = args .get (2 );
9187 JavaTemplate .Builder template = TypeUtils .isString (message .getType ()) ?
9288 JavaTemplate .builder ("assertThat(#{anyArray()}).as(#{any(String)}).containsExactly(#{anyArray()});" ) :
9389 JavaTemplate .builder ("assertThat(#{anyArray()}).as(#{any(java.util.function.Supplier)}).containsExactly(#{anyArray()});" );
94-
95- method = method .withTemplate (template
96- .staticImports ("org.assertj.core.api.Assertions.assertThat" )
97- .javaParser (assertionsParser (ctx ))
98- .build (),
99- getCursor (),
100- method .getCoordinates ().replace (),
101- actual ,
102- message ,
103- expected
104- );
90+ return template
91+ .staticImports ("org.assertj.core.api.Assertions.assertThat" )
92+ .javaParser (assertionsParser (ctx ))
93+ .build ()
94+ .apply (getCursor (), method .getCoordinates ().replace (), actual , message , expected );
10595 } else if (args .size () == 3 ) {
106- // assert is using floating points with a delta and no message.
107- method = method .withTemplate (
108- JavaTemplate .builder ("assertThat(#{anyArray()}).containsExactly(#{anyArray()}, within(#{any()}));" )
109- .context (getCursor ())
110- .staticImports ("org.assertj.core.api.Assertions.assertThat" , "org.assertj.core.api.Assertions.within" )
111- .javaParser (assertionsParser (ctx ))
112- .build (),
113- getCursor (),
114- method .getCoordinates ().replace (),
115- actual ,
116- expected ,
117- args .get (2 )
118- );
119- maybeAddImport ("org.assertj.core.api.Assertions" , "within" );
120- } else {
121- // The assertEquals is using a floating point with a delta argument and a message.
122- Expression message = args .get (3 );
123- JavaTemplate .Builder template = TypeUtils .isString (message .getType ()) ?
124- JavaTemplate .builder ("assertThat(#{anyArray()}).as(#{any(String)}).containsExactly(#{anyArray()}, within(#{any()}));" ) :
125- JavaTemplate .builder ("assertThat(#{anyArray()}).as(#{any(java.util.function.Supplier)}).containsExactly(#{anyArray()}, within(#{}));" );
126-
127- method = method .withTemplate (template
128- .context (getCursor ())
129- .staticImports ("org.assertj.core.api.Assertions.assertThat" , "org.assertj.core.api.Assertions.within" )
130- .javaParser (assertionsParser (ctx ))
131- .build (),
132- getCursor (),
133- method .getCoordinates ().replace (),
134- actual ,
135- message ,
136- expected ,
137- args .get (2 )
138- );
13996 maybeAddImport ("org.assertj.core.api.Assertions" , "within" );
97+ // assert is using floating points with a delta and no message.
98+ return JavaTemplate .builder ("assertThat(#{anyArray()}).containsExactly(#{anyArray()}, within(#{any()}));" )
99+ .staticImports ("org.assertj.core.api.Assertions.assertThat" , "org.assertj.core.api.Assertions.within" )
100+ .javaParser (assertionsParser (ctx ))
101+ .build ()
102+ .apply (getCursor (), method .getCoordinates ().replace (), actual , expected , args .get (2 ));
140103 }
141104
142- maybeAddImport ("org.assertj.core.api.Assertions" , "assertThat" );
143- maybeRemoveImport (JUNIT_QUALIFIED_ASSERTIONS_CLASS_NAME );
144-
145- return method ;
105+ // The assertEquals is using a floating point with a delta argument and a message.
106+ Expression message = args .get (3 );
107+ maybeAddImport ("org.assertj.core.api.Assertions" , "within" );
108+
109+ JavaTemplate .Builder template = TypeUtils .isString (message .getType ()) ?
110+ JavaTemplate .builder ("assertThat(#{anyArray()}).as(#{any(String)}).containsExactly(#{anyArray()}, within(#{any()}));" ) :
111+ JavaTemplate .builder ("assertThat(#{anyArray()}).as(#{any(java.util.function.Supplier)}).containsExactly(#{anyArray()}, within(#{}));" );
112+ return template
113+ .staticImports ("org.assertj.core.api.Assertions.assertThat" , "org.assertj.core.api.Assertions.within" )
114+ .javaParser (assertionsParser (ctx ))
115+ .build ()
116+ .apply (getCursor (), method .getCoordinates ().replace (), actual , message , expected , args .get (2 ));
146117 }
147118
148119 /**
0 commit comments