Skip to content

Commit 3f809dd

Browse files
framierejdubois
authored andcommitted
Suite à la discussion à 973a1f6
Et pour le plaisir utilise mockito et festAssert
1 parent e8fd8cf commit 3f809dd

3 files changed

Lines changed: 41 additions & 27 deletions

File tree

‎pom.xml‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,18 @@
113113
<artifactId>junit</artifactId>
114114
<version>4.8.2</version>
115115
</dependency>
116-
<dependency>
117-
<groupId>org.easymock</groupId>
118-
<artifactId>easymock</artifactId>
119-
<version>3.0</version>
120-
</dependency>
116+
<dependency>
117+
<groupId>org.mockito</groupId>
118+
<artifactId>mockito-all</artifactId>
119+
<version>1.8.5</version>
120+
<scope>test</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.easytesting</groupId>
124+
<artifactId>fest-assert</artifactId>
125+
<version>1.3</version>
126+
<scope>test</scope>
127+
</dependency>
121128
<dependency>
122129
<groupId>org.springframework</groupId>
123130
<artifactId>spring-test</artifactId>

‎src/main/java/fr/ippon/rh/web/IpponController.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
@Controller
1515
public class IpponController {
1616

17+
private final OffreService offreService;
18+
1719
@Inject
18-
private OffreService offreService;
20+
public IpponController(OffreService offreService) {
21+
this.offreService = offreService;
22+
}
1923

2024
/**
2125
* Affiche l'offre.
@@ -26,4 +30,3 @@ public String ipponRecrute(Model model) {
2630
return "ippon";
2731
}
2832
}
29-
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package fr.ippon.rh.web;
22

3-
import fr.ippon.rh.service.OffreService;
3+
import static junit.framework.Assert.assertEquals;
4+
import static junit.framework.Assert.assertNotNull;
5+
import static org.fest.assertions.Assertions.assertThat;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.times;
8+
import static org.mockito.Mockito.verify;
9+
import static org.mockito.Mockito.when;
10+
11+
import org.fest.assertions.Assertions;
412
import org.junit.Before;
513
import org.junit.Test;
6-
import org.springframework.test.util.ReflectionTestUtils;
14+
import org.mockito.Mockito;
715
import org.springframework.ui.ExtendedModelMap;
816

9-
import static junit.framework.Assert.assertEquals;
10-
import static junit.framework.Assert.assertNotNull;
11-
import static org.easymock.EasyMock.*;
17+
import fr.ippon.rh.service.OffreService;
1218

1319
/**
1420
* Test de la classe {@link IpponController}
@@ -19,30 +25,28 @@ public class IpponControllerTest {
1925
private OffreService mockOffreService;
2026

2127
@Before
22-
public void setUp(){
23-
//Init
24-
controller = new IpponController();
25-
mockOffreService = createMock(OffreService.class);
26-
ReflectionTestUtils.setField(controller, "offreService", mockOffreService);
28+
public void setUp() {
29+
mockOffreService = mock(OffreService.class);
30+
controller = new IpponController(mockOffreService);
2731
}
2832

2933
@Test
30-
public void testIpponRecruteGet(){
31-
//Expect
34+
public void testIpponRecruteGet() {
35+
// Expect
3236
ExtendedModelMap model = new ExtendedModelMap();
3337
String text = "Offre";
34-
expect(mockOffreService.getOffre()).andReturn(text);
38+
when(mockOffreService.getOffre()).thenReturn(text);
3539

3640
// When
37-
replay(mockOffreService);
3841
String returnViewName = controller.ipponRecrute(model);
3942

4043
// Verify
41-
verify(mockOffreService);
42-
assertNotNull(returnViewName);
43-
assertEquals("ippon", returnViewName);
44-
assertEquals(1, model.size());
45-
assertNotNull(model.get("offre"));
46-
assertEquals(text, model.get("offre"));
44+
verify(mockOffreService, times(1)).getOffre();
45+
assertThat(returnViewName).isNotNull();
46+
assertThat(returnViewName).isEqualTo("ippon");
47+
assertThat(model).isNotNull();
48+
assertThat(model).hasSize(1);
49+
assertThat(model.get("offre")).isNotNull();
50+
assertThat(model.get("offre")).isEqualTo(text);
4751
}
4852
}

0 commit comments

Comments
 (0)