Skip to content

Commit cbedf1d

Browse files
author
cristiii
committed
added couple of tests springframeworkguru#3
1 parent 5071230 commit cbedf1d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package guru.springframework.sfgpetclinic.controllers;
2+
3+
import guru.springframework.sfgpetclinic.fauxspring.Model;
4+
import guru.springframework.sfgpetclinic.fauxspring.ModelMapImpl;
5+
import guru.springframework.sfgpetclinic.model.Vet;
6+
import guru.springframework.sfgpetclinic.services.SpecialtyService;
7+
import guru.springframework.sfgpetclinic.services.VetService;
8+
import guru.springframework.sfgpetclinic.services.map.SpecialityMapService;
9+
import guru.springframework.sfgpetclinic.services.map.VetMapService;
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static org.junit.jupiter.api.Assertions.*;
14+
15+
class VetControllerTest {
16+
17+
private VetController vetController;
18+
private VetService vetService;
19+
private SpecialtyService specialtyService;
20+
Vet vet1;
21+
Vet vet2;
22+
@BeforeEach
23+
void setUp() {
24+
specialtyService = new SpecialityMapService();
25+
vetService = new VetMapService(specialtyService);
26+
vetController = new VetController(vetService);
27+
vet1 = new Vet(1l, "joe", "buck", null);
28+
vet2 = new Vet(2l, "joe", "biden", null);
29+
30+
vetService.save(vet1);
31+
vetService.save(vet2);
32+
}
33+
34+
@Test
35+
void listVets() {
36+
Model model = new ModelMapImpl();
37+
assertEquals("vets/index", vetController.listVets(model));
38+
assertEquals(2, ((ModelMapImpl) model).getMap().size());
39+
}
40+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package guru.springframework.sfgpetclinic.fauxspring;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
public class ModelMapImpl implements Model{
9+
public Map<String, Object> getMap() {
10+
return map;
11+
}
12+
13+
Map<String, Object> map = new HashMap<>();
14+
@Override
15+
public void addAttribute(String key, Object o) {
16+
map.put(key, o );
17+
}
18+
19+
@Override
20+
public void addAttribute(Object o) {
21+
// do nothing
22+
}
23+
}

0 commit comments

Comments
 (0)