HardcodedStackVersionPropertiesCheck extends AbstractCheckDescriptor { public static boolean stringContainsVersionHardcode(String string, Pattern searchPattern) { Matcher matcher = searchPattern.matcher(string); return matcher.find(); } HardcodedStackVersionPropertiesCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); static Pattern getHardcodeSearchPattern(String hdpVersion); static boolean stringContainsVersionHardcode(String string, Pattern searchPattern);  }
@Test public void testStringContainsVersionHardcode() throws Exception { Pattern pattern = HardcodedStackVersionPropertiesCheck.getHardcodeSearchPattern(currentVersion); String content = ""; assertFalse(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern)); content = "2.3.4.0-1234"; assertTrue(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern)); content = "dfsdfds fdsfds -Dhdp.version=2.3.4.0-1234 sfdfdsfds"; assertFalse(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern)); content = "dfsdfds fdsfds -Dhdp.version=2.3.4.0-1234 \n sfdfdsfds 2.3.4.0-1234 \n fdsfds"; assertTrue(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern)); content = "hdp.version=2.3.4.0-1234"; assertTrue(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern)); content = "kgflkfld fdf\nld;ls;f d hdp.version=2.3.4.0-1234 \n sfdfdsfds \n fdsfds"; assertTrue(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern)); }