Test all new methods

This commit is contained in:
cugurlu
2019-03-31 15:27:07 +02:00
parent 3b4add03ee
commit f4f79484fa
3 changed files with 39 additions and 0 deletions

View File

@@ -11,7 +11,9 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(MockitoJUnitRunner.class)
public class UserServiceTest {
@@ -86,6 +88,17 @@ public class UserServiceTest {
Assert.assertEquals(estimate, result);
}
@Test
public void getInputsTest() throws Exception {
Map<String, String> estimate = new HashMap<>();
estimate.put("Eric", "3");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getInputs?name=Eric"),
Map.class))
.thenReturn(estimate);
Map<String, String> result = userService.getInputs("Eric");
Assert.assertEquals(estimate, result);
}
@Test
public void setInputTest() throws Exception {
userService.updateInput("Eric", "input_size", "5");

View File

@@ -94,6 +94,19 @@ public class UserControllerTest {
assertEquals("merel", arg2Captor.getValue());
}
@Test
public void getInputMapTest() throws Exception {
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
mvc.perform(get("/getInputs")
.param("name", "ceren")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());
verify(userService, times(1))
.getInputMap(arg1Captor.capture());
assertEquals("ceren", arg1Captor.getValue());
}
@Test
public void getAllUsersTest() throws Exception {
mvc.perform(get("/getAllUsers")

View File

@@ -20,7 +20,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(SpringRunner.class)
public class UserServiceTest {
@@ -136,6 +138,17 @@ public class UserServiceTest {
.getInput("alex", "input_footprint_shopping_food_dairy_default"));
}
@Test
public void getInputMapTest() {
Map<String, String> map = new HashMap<>();
User alex = new User(1L, "alex", "password");
when(userRepository.findByName(alex.getName()))
.thenReturn(alex);
alex.setFootPrintInputs(map);
assertEquals(map, userService
.getInputMap("alex"));
}
@Test
public void getInputExceptionTest() {
assertThrows(ApplicationException.class, () -> userService.getInput("alex", "hello"));