@Test public void test_should_notmatch_create_user_And_expecteduser() { List<UserSearchResponseContent> list = new ArrayList<UserSearchResponseContent>(); UserSearchResponseContent searchContent = new UserSearchResponseContent(1l, "test@gmail.com", "123456789"); list.add(searchContent); Map<String, Object> map = new HashMap<String, Object>(); map.put("user", list); when(restTemplate.postForObject(any(String.class), any(UserSearchRequest.class), eq(Map.class))) .thenReturn(map); User actualUser = userRepository.fetchUser("123456789", "tenantId", "CITIZEN"); final User expectedUser = new User(2L, "test123@gmail.com", "123456789"); assertNotEquals(expectedUser, actualUser); }
public User fetchUser(String mobileNumber, String tenantId, String userType) { final UserSearchRequest request = new UserSearchRequest(mobileNumber, tenantId, userType); ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); try { Map<String, Object> response = restTemplate.postForObject(HOST + SEARCH_USER_URL, request, Map.class); List<UserSearchResponseContent> users = (List<UserSearchResponseContent>) response.get("user"); if (!users.isEmpty()) { UserSearchResponseContent user = mapper.convertValue(users.get(0), UserSearchResponseContent.class); return new User(user.getId(), user.getEmailId(), user.getMobileNumber()); } else { return null; } } catch (Exception e) { log.info("Excpetion WhileFetching User from user : " + e.getMessage()); } return null; }
UserRepository { public User fetchUser(String mobileNumber, String tenantId, String userType) { final UserSearchRequest request = new UserSearchRequest(mobileNumber, tenantId, userType); ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); try { Map<String, Object> response = restTemplate.postForObject(HOST + SEARCH_USER_URL, request, Map.class); List<UserSearchResponseContent> users = (List<UserSearchResponseContent>) response.get("user"); if (!users.isEmpty()) { UserSearchResponseContent user = mapper.convertValue(users.get(0), UserSearchResponseContent.class); return new User(user.getId(), user.getEmailId(), user.getMobileNumber()); } else { return null; } } catch (Exception e) { log.info("Excpetion WhileFetching User from user : " + e.getMessage()); } return null; } }
UserRepository { public User fetchUser(String mobileNumber, String tenantId, String userType) { final UserSearchRequest request = new UserSearchRequest(mobileNumber, tenantId, userType); ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); try { Map<String, Object> response = restTemplate.postForObject(HOST + SEARCH_USER_URL, request, Map.class); List<UserSearchResponseContent> users = (List<UserSearchResponseContent>) response.get("user"); if (!users.isEmpty()) { UserSearchResponseContent user = mapper.convertValue(users.get(0), UserSearchResponseContent.class); return new User(user.getId(), user.getEmailId(), user.getMobileNumber()); } else { return null; } } catch (Exception e) { log.info("Excpetion WhileFetching User from user : " + e.getMessage()); } return null; }  }
UserRepository { public User fetchUser(String mobileNumber, String tenantId, String userType) { final UserSearchRequest request = new UserSearchRequest(mobileNumber, tenantId, userType); ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); try { Map<String, Object> response = restTemplate.postForObject(HOST + SEARCH_USER_URL, request, Map.class); List<UserSearchResponseContent> users = (List<UserSearchResponseContent>) response.get("user"); if (!users.isEmpty()) { UserSearchResponseContent user = mapper.convertValue(users.get(0), UserSearchResponseContent.class); return new User(user.getId(), user.getEmailId(), user.getMobileNumber()); } else { return null; } } catch (Exception e) { log.info("Excpetion WhileFetching User from user : " + e.getMessage()); } return null; }  User fetchUser(String mobileNumber, String tenantId, String userType); }
UserRepository { public User fetchUser(String mobileNumber, String tenantId, String userType) { final UserSearchRequest request = new UserSearchRequest(mobileNumber, tenantId, userType); ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); try { Map<String, Object> response = restTemplate.postForObject(HOST + SEARCH_USER_URL, request, Map.class); List<UserSearchResponseContent> users = (List<UserSearchResponseContent>) response.get("user"); if (!users.isEmpty()) { UserSearchResponseContent user = mapper.convertValue(users.get(0), UserSearchResponseContent.class); return new User(user.getId(), user.getEmailId(), user.getMobileNumber()); } else { return null; } } catch (Exception e) { log.info("Excpetion WhileFetching User from user : " + e.getMessage()); } return null; }  User fetchUser(String mobileNumber, String tenantId, String userType);  }