1212import org .junit .Test ;
1313import org .junit .runner .RunWith ;
1414
15- /**
16- * <p>Test for LoginController using JMockit.</p>
17- * Created by Alvaro on 12/06/2016.
18- */
1915@ RunWith (JMockit .class )
2016public class LoginControllerTest {
2117
@@ -32,66 +28,77 @@ public class LoginControllerTest {
3228 public void assertThatNoMethodHasBeenCalled () {
3329 loginController .login (null );
3430 // no method called
35- new FullVerifications (loginService ) {};
31+ new FullVerifications (loginService ) {
32+ };
3633 }
3734
3835 @ Test
3936 public void assertTwoMethodsHaveBeenCalled () {
4037 final UserForm userForm = new UserForm ();
4138 userForm .username = "foo" ;
4239 new Expectations () {{
43- loginService .login (userForm ); result = true ;
40+ loginService .login (userForm );
41+ result = true ;
4442 loginService .setCurrentUser ("foo" );
4543 }};
4644
4745 String login = loginController .login (userForm );
4846
4947 Assert .assertEquals ("OK" , login );
50- new FullVerifications (loginService ) {};
48+ new FullVerifications (loginService ) {
49+ };
5150 }
5251
5352 @ Test
5453 public void assertOnlyOneMethodHasBeenCalled () {
5554 final UserForm userForm = new UserForm ();
5655 userForm .username = "foo" ;
5756 new Expectations () {{
58- loginService .login (userForm ); result = false ;
57+ loginService .login (userForm );
58+ result = false ;
5959 // no expectation for setCurrentUser
6060 }};
6161
6262 String login = loginController .login (userForm );
6363
6464 Assert .assertEquals ("KO" , login );
65- new FullVerifications (loginService ) {};
65+ new FullVerifications (loginService ) {
66+ };
6667 }
6768
6869 @ Test
6970 public void mockExceptionThrowing () {
7071 final UserForm userForm = new UserForm ();
7172 new Expectations () {{
72- loginService .login (userForm ); result = new IllegalArgumentException ();
73+ loginService .login (userForm );
74+ result = new IllegalArgumentException ();
7375 // no expectation for setCurrentUser
7476 }};
7577
7678 String login = loginController .login (userForm );
7779
7880 Assert .assertEquals ("ERROR" , login );
79- new FullVerifications (loginService ) {};
81+ new FullVerifications (loginService ) {
82+ };
8083 }
8184
8285 @ Test
8386 public void mockAnObjectToPassAround (@ Mocked final UserForm userForm ) {
8487 new Expectations () {{
85- userForm .getUsername (); result = "foo" ;
86- loginService .login (userForm ); result = true ;
88+ userForm .getUsername ();
89+ result = "foo" ;
90+ loginService .login (userForm );
91+ result = true ;
8792 loginService .setCurrentUser ("foo" );
8893 }};
89-
94+
9095 String login = loginController .login (userForm );
9196
9297 Assert .assertEquals ("OK" , login );
93- new FullVerifications (loginService ) {};
94- new FullVerifications (userForm ) {};
98+ new FullVerifications (loginService ) {
99+ };
100+ new FullVerifications (userForm ) {
101+ };
95102 }
96103
97104 @ Test
@@ -119,7 +126,8 @@ public void describeTo(Description description) {
119126 String login = loginController .login (userForm );
120127
121128 Assert .assertEquals ("OK" , login );
122- new FullVerifications (loginService ) {};
129+ new FullVerifications (loginService ) {
130+ };
123131 }
124132
125133 @ Test
@@ -133,7 +141,8 @@ public void partialMocking() {
133141 userForm .username = "foo" ;
134142 // let service's login use implementation so let's mock DAO call
135143 new Expectations () {{
136- loginDao .login (userForm ); result = 1 ;
144+ loginDao .login (userForm );
145+ result = 1 ;
137146 // no expectation for loginService.login
138147 partialLoginService .setCurrentUser ("foo" );
139148 }};
@@ -142,7 +151,9 @@ public void partialMocking() {
142151
143152 Assert .assertEquals ("OK" , login );
144153 // verify mocked call
145- new FullVerifications (partialLoginService ) {};
146- new FullVerifications (loginDao ) {};
154+ new FullVerifications (partialLoginService ) {
155+ };
156+ new FullVerifications (loginDao ) {
157+ };
147158 }
148159}
0 commit comments