@Test public void testConvert5() throws Exception { ConvertService dummyConvertService = mock(ConvertService.class); when(dummyConvertService.convert(anyObject())).thenThrow(RuntimeException.class); EagleController controller = new EagleController(); ReflectionTestUtils.setField(controller, "convertService", dummyConvertService); MockMvc mvc = standaloneSetup(controller).build(); mvc.perform( MockMvcRequestBuilders.get("/convert/uah/usd/100").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.status", is("500"))); }
@Before public void setUp() { dummyConvertService = mock(ConvertService.class); when(dummyConvertService.convert(anyObject())).thenReturn(new BigDecimal(150)); controller = new EagleController(); ReflectionTestUtils.setField(controller, "convertService", dummyConvertService); mvc = standaloneSetup(controller).build(); }
@Test public void testConvert7() throws Exception { ConvertService dummyConvertService = mock(ConvertService.class); when(dummyConvertService.convert(anyObject())).thenReturn(new BigDecimal(150)); EagleController controller = new EagleController(); ReflectionTestUtils.setField(controller, "convertService", dummyConvertService); MockMvc mvc = standaloneSetup(controller).build(); mvc.perform( MockMvcRequestBuilders.get("/convert/uah/usd/100") .header("user-agent", "") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.status", is("200"))); mvc = standaloneSetup(controller).build(); mvc.perform( MockMvcRequestBuilders.get("/convert/uah/usd/100") .header("user-agent", "Mozilla Opera, Safari Ie TEST TES TTT") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.status", is("200"))); }