Guest User

test

a guest
Jan 19th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. Shop shop1 = Shop.builder().id(1).latitude(1.1).longitude(2.2).name("shop1").build();
  2.         Shop shop2 = Shop.builder().id(2).latitude(10.1).longitude(20.2).name("shop2").build();
  3.  
  4.         UserPosition userPosition = new UserPosition(1L, 0.0, 0.0, 10.0);
  5.  
  6.         when(shopServiceMock.searchWithinRadius(0.0, 0.0, 10.0, 1, 10)).thenReturn(Arrays.asList(shop1, shop2));
  7.  
  8.         ObjectMapper objectMapper = new ObjectMapper();
  9.         byte[] jsonUserPosition = objectMapper.writeValueAsBytes(userPosition);
  10.  
  11.         mockMvc.perform(get("/api/shops/searchWithinRadius")
  12.                 .contentType(TestUtil.APPLICATION_JSON_UTF8).content(jsonUserPosition)
  13.                 .param("page", "1").param("size", "10"))
  14.                 .andExpect(status().isOk())
  15.                 .andExpect(content().contentType(TestUtil.APPLICATION_JSON_UTF8))
  16.                 .andExpect(jsonPath("$", hasSize(2)))
  17.                 .andExpect(jsonPath("$[0].id", is(1)))
  18.                 .andExpect(jsonPath("$[0].name", is("shop1")))
  19.                 .andExpect(jsonPath("$[1].id", is(2)))
  20.                 .andExpect(jsonPath("$[1].name", is("shop2")));
  21.  
  22.         verify(shopServiceMock, times(1)).searchWithinRadius(0.0, 0.0, 10.0, 1, 10);
Add Comment
Please, Sign In to add comment