@Test public void testisValidTargetType() throws Exception { List<Map<String, Object>> tTypeList = new ArrayList<>(); Map<String, Object> tTypeMap = new HashMap<>(); tTypeMap.put("type", "ec2"); tTypeMap.put("category", "aws-all"); tTypeMap.put("domain", "Infra & Platforms"); tTypeList.add(tTypeMap); when(service.getTargetTypesForAssetGroup(anyObject(), anyObject(), anyString())).thenReturn(tTypeList); ReflectionTestUtils.setField(Util.class, "assetService", service); boolean valid = Util.isValidTargetType("aws-all", "ec2"); assertTrue(valid); doThrow(new NullPointerException()).when(service).getTargetTypesForAssetGroup(anyObject(), anyObject(), anyString()); valid = Util.isValidTargetType("aws-all", "ec2"); assertTrue(!valid); }
public static boolean isValidTargetType(String ag, String type) { try { List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null, null); return targetTypes.stream().filter(obj -> type.equals(obj.get("type"))).count() > 0 ? true : false; } catch (Exception e) { LOGGER.error("Error in isValidTargetType ",e); return false; } }
Util { public static boolean isValidTargetType(String ag, String type) { try { List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null, null); return targetTypes.stream().filter(obj -> type.equals(obj.get("type"))).count() > 0 ? true : false; } catch (Exception e) { LOGGER.error("Error in isValidTargetType ",e); return false; } } }
Util { public static boolean isValidTargetType(String ag, String type) { try { List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null, null); return targetTypes.stream().filter(obj -> type.equals(obj.get("type"))).count() > 0 ? true : false; } catch (Exception e) { LOGGER.error("Error in isValidTargetType ",e); return false; } }  }
Util { public static boolean isValidTargetType(String ag, String type) { try { List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null, null); return targetTypes.stream().filter(obj -> type.equals(obj.get("type"))).count() > 0 ? true : false; } catch (Exception e) { LOGGER.error("Error in isValidTargetType ",e); return false; } }  @Autowired(required = true) void setassetService(AssetService assetService); static boolean isValidTargetType(String ag, String type); static boolean isValidAssetGroup(String ag); static int getUtilisationScore(double cpuUtilisation); static String encodeUrl(String toBeEncoded); }
Util { public static boolean isValidTargetType(String ag, String type) { try { List<Map<String, Object>> targetTypes = assetService.getTargetTypesForAssetGroup(ag, null, null); return targetTypes.stream().filter(obj -> type.equals(obj.get("type"))).count() > 0 ? true : false; } catch (Exception e) { LOGGER.error("Error in isValidTargetType ",e); return false; } }  @Autowired(required = true) void setassetService(AssetService assetService); static boolean isValidTargetType(String ag, String type); static boolean isValidAssetGroup(String ag); static int getUtilisationScore(double cpuUtilisation); static String encodeUrl(String toBeEncoded);  }