BadgeClassExtensionServiceImpl implements BadgeClassExtensionService { @Override public BadgeClassExtension get(String badgeId) throws ProjectCommonException { Response response = cassandraOperation.getRecordById(Util.KEY_SPACE_NAME, BADGE_CLASS_EXT_TABLE_NAME, badgeId); List<Map<String, Object>> badgeList = (List<Map<String, Object>>) response.get(JsonKey.RESPONSE); if ((badgeList == null) || badgeList.isEmpty()) { ProjectLogger.log( "BadgeClassExtensionServiceImpl:get: Badge not found " + badgeId, LoggerEnum.ERROR.name()); throw new ProjectCommonException( ResponseCode.resourceNotFound.getErrorCode(), ResponseCode.resourceNotFound.getErrorMessage(), ResponseCode.RESOURCE_NOT_FOUND.getResponseCode()); } return new BadgeClassExtension(badgeList.get(0)); } BadgeClassExtensionServiceImpl();  BadgeClassExtensionServiceImpl(CassandraOperation cassandraOperation); @Override void save(BadgeClassExtension badgeClassExtension); @Override List<BadgeClassExtension> search(
      List<String> issuerList,
      List<String> badgeList,
      String rootOrgId,
      String type,
      String subtype,
      List<String> roles); @Override BadgeClassExtension get(String badgeId); @Override void delete(String badgeId); static final String BADGE_CLASS_EXT_TABLE_NAME; }
@Test public void testGetSuccess() { Response response = new Response(); response.put( JsonKey.RESPONSE, new ArrayList<Map<String, Object>>(Arrays.asList(new HashMap<>()))); PowerMockito.when( mockDBService.getRecordById(Mockito.any(), Mockito.any(), Mockito.anyString())) .thenReturn(response); BadgeClassExtension badgeClassExtension = badgeClassExtensionServiceImpl.get(VALUE_BADGE_ID); Assert.assertTrue(null != badgeClassExtension); }
@Test public void testGetFailureBadgeListNull() { Response response = new Response(); response.put(JsonKey.RESPONSE, new ArrayList<Map<String, Object>>()); PowerMockito.when( mockDBService.getRecordById(Mockito.any(), Mockito.any(), Mockito.anyString())) .thenReturn(new Response()); boolean thrown = false; try { badgeClassExtensionServiceImpl.get(VALUE_BADGE_ID); } catch (ProjectCommonException exception) { thrown = true; Assert.assertEquals( ResponseCode.RESOURCE_NOT_FOUND.getResponseCode(), exception.getResponseCode()); } Assert.assertEquals(true, thrown); }
@Test public void testGetFailureBadgeListEmpty() { Response response = new Response(); response.put(JsonKey.RESPONSE, new ArrayList<Map<String, Object>>()); PowerMockito.when( mockDBService.getRecordById(Mockito.any(), Mockito.any(), Mockito.anyString())) .thenReturn(response); boolean thrown = false; try { badgeClassExtensionServiceImpl.get(VALUE_BADGE_ID); } catch (ProjectCommonException exception) { thrown = true; Assert.assertEquals( ResponseCode.RESOURCE_NOT_FOUND.getResponseCode(), exception.getResponseCode()); } Assert.assertEquals(true, thrown); }