GitBlameCommand extends Command { String textUnitNameToTextUnitNameInSource(String textUnitName, FileType fileType, boolean isPluralForm) { String textUnitNameInSource = textUnitName; Pattern pattern = getTextUnitNameToTextUnitNameInSourcePattern(fileType, isPluralForm); if (pattern != null) { Matcher matcher = pattern.matcher(textUnitName); if (matcher.matches()) { textUnitNameInSource = matcher.group(GROUP_NAME_FOR_TEXT_UNIT_NAME_IN_SOURCE); logger.debug("string in source file: {}", textUnitNameInSource); } else { throw new IllegalArgumentException("The pattern to extract the 'text unit name in source' must match. For text unit name: " + textUnitName); } } return textUnitNameInSource; }  @Override void execute(); List<GitBlameWithUsage> getGitBlameWithUsagesToProcess(List<GitBlameWithUsage> gitBlameWithUsages);  }
@Test public void textUnitNameToTextUnitNameInSourceDefault() { GitBlameCommand gitBlameCommand = new GitBlameCommand(); FileType fileType = new POFileType(); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test", fileType, false)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test _zero", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test _one", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test _two", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test _few", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test _many", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test _other", fileType, true)); assertEquals("test_test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_test", fileType, false)); assertEquals("test_test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_test _one", fileType, true)); }
@Test public void textUnitNameToTextUnitNameInSourceAndroid() { GitBlameCommand gitBlameCommand = new GitBlameCommand(); FileType fileType = new AndroidStringsFileType(); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test", fileType, false)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_zero", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_one", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_two", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_few", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_many", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_other", fileType, true)); assertEquals("test_test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_test", fileType, false)); assertEquals("test_test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_test_one", fileType, true)); assertEquals("test", gitBlameCommand.textUnitNameToTextUnitNameInSource("test_1", fileType, false)); }
@Test public void textUnitNameToTextUnitNameInSourceChromeExtJson() { GitBlameCommand gitBlameCommand = new GitBlameCommand(); FileType fileType = new ChromeExtensionJSONFileType(); assertEquals("hello", gitBlameCommand.textUnitNameToTextUnitNameInSource("hello/message", fileType, false)); assertEquals("hello/message_zero", gitBlameCommand.textUnitNameToTextUnitNameInSource("hello/message_zero", fileType, true)); try { gitBlameCommand.textUnitNameToTextUnitNameInSource("hello_zero", fileType, false); fail("should throw an exception if the regex doesn't match"); } catch (IllegalArgumentException iae) { assertEquals("The pattern to extract the 'text unit name in source' must match. For text unit name: hello_zero", iae.getMessage()); } }