@@ -14,23 +14,23 @@ public class OperationsUnitTest {
1414 public OperationsUnitTest () {
1515 }
1616
17- @ Test (expected = IllegalAccessException .class )
18- public void givenObject_whenInvokePrivatedMethod_thenFail () throws NoSuchMethodException , IllegalAccessException , IllegalArgumentException , InvocationTargetException {
19- Method andInstanceMethod = Operations .class .getDeclaredMethod ("and" , boolean .class , boolean .class );
17+ @ Test (expected = IllegalAccessException .class )
18+ public void givenObject_whenInvokePrivateMethod_thenFail () throws NoSuchMethodException , IllegalAccessException , IllegalArgumentException , InvocationTargetException {
19+ Method andPrivateMethod = Operations .class .getDeclaredMethod ("and" , boolean .class , boolean .class );
2020
2121 Operations operationsInstance = new Operations ();
22- Boolean result = (Boolean )andInstanceMethod .invoke (operationsInstance , true , false );
22+ Boolean result = (Boolean ) andPrivateMethod .invoke (operationsInstance , true , false );
2323
2424 assertFalse (result );
2525 }
2626
2727 @ Test
2828 public void givenObject_whenInvokePrivateMethod_thenCorrect () throws Exception {
29- Method andInstanceMethod = Operations .class .getDeclaredMethod ("and" , boolean .class , boolean .class );
30- andInstanceMethod .setAccessible (true );
29+ Method andPrivatedMethod = Operations .class .getDeclaredMethod ("and" , boolean .class , boolean .class );
30+ andPrivatedMethod .setAccessible (true );
3131
3232 Operations operationsInstance = new Operations ();
33- Boolean result = (Boolean )andInstanceMethod .invoke (operationsInstance , true , false );
33+ Boolean result = (Boolean ) andPrivatedMethod .invoke (operationsInstance , true , false );
3434
3535 assertFalse (result );
3636 }
@@ -40,17 +40,17 @@ public void givenObject_whenInvokePublicMethod_thenCorrect() throws Exception {
4040 Method sumInstanceMethod = Operations .class .getMethod ("sum" , int .class , double .class );
4141
4242 Operations operationsInstance = new Operations ();
43- Double result = (Double )sumInstanceMethod .invoke (operationsInstance , 1 , 3 );
44-
43+ Double result = (Double ) sumInstanceMethod .invoke (operationsInstance , 1 , 3 );
44+
4545 assertThat (result , equalTo (4.0 ));
4646 }
47-
47+
4848 @ Test
4949 public void givenObject_whenInvokeStaticMethod_thenCorrect () throws Exception {
50- Method multiplyStaticMethod = Operations .class .getDeclaredMethod ("multiply" ,float .class , long .class );
50+ Method multiplyStaticMethod = Operations .class .getDeclaredMethod ("multiply" , float .class , long .class );
51+
52+ Double result = (Double ) multiplyStaticMethod .invoke (null , 3.5f , 2 );
5153
52- Double result = (Double )multiplyStaticMethod .invoke (null , 3.5f , 2 );
53-
5454 assertThat (result , equalTo (7.0 ));
5555 }
5656
0 commit comments