### Question:
NotificationServiceImpl implements NotificationService,Constants { public Map<String,Object> getDeviceDetails(String deviceId) throws Exception{ Map<String, Object> mustFilter= new HashMap<>(); mustFilter.put("_id", deviceId); List<Map<String,Object>> response = elasticSearchRepository.getSortedDataFromES("pac_cache", "element", mustFilter, null, null, null,null, null); if(null!=response) return response.get(0); else throw new Exception("no data found"); }  @Override List<Map<String, Object>> getApiRoles(String serviceProject, String environment); Map<String,Object> getDeviceDetails(String deviceId); @Override List<Map<String,Object>> getAllAssetGroupOwnerEmailDetails(); @Override Map<String, Object> unsubscribeDigestMail(final String mailId); @Override Map<String, Object> subscribeDigestMail(String mailId);  }### Answer:
@Test public void getDeviceDetailsTest()throws Exception{ List<Map<String,Object>> response=new ArrayList<>(); List<Map<String,Object>> emptyResponse=null; Map<String,Object>deviceDetails = new HashMap<>(); deviceDetails.put("_id", "amz1123444"); deviceDetails.put("name", "Nicholas Criss"); deviceDetails.put("callme", "Nick"); deviceDetails.put("email", "nick@testemail.com"); response.add(deviceDetails); when(elasticSearchRepository.getSortedDataFromES(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject())).thenReturn(response); notificationImpl.getDeviceDetails("1"); when(elasticSearchRepository.getSortedDataFromES(anyString(), anyString(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject())).thenReturn(emptyResponse); assertThatThrownBy( () -> notificationImpl.getDeviceDetails("1")).isInstanceOf(Exception.class); }