GrepDelegator extends BaseDelegator implements IGrepDelegator { public List<IFileLineMatch> getMatchingLines(final List<IFileSpec> fileSpecs, final String pattern, final MatchingLinesOptions options) throws P4JavaException { return getMatchingLines(fileSpecs, pattern, null, options); } GrepDelegator(final IOptionsServer server); List<IFileLineMatch> getMatchingLines(final List<IFileSpec> fileSpecs,
            final String pattern, final MatchingLinesOptions options); List<IFileLineMatch> getMatchingLines(@Nonnull final List<IFileSpec> fileSpecs,
            // p4ic4idea: use IServerMessage for info lines.
            @Nonnull final String pattern, @Nullable final List<IServerMessage> infoLines,
            final MatchingLinesOptions options);  }
@Test(expected = ConnectionException.class) public void testGrepOptConnectionException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(ConnectionException.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, new MatchingLinesOptions()); }
@Test(expected = ConnectionException.class) public void testGrepOptInfoConnectionException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(ConnectionException.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, null, new MatchingLinesOptions()); }
@Test(expected = AccessException.class) public void testGrepOptAccessException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(AccessException.AccessExceptionForTests.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, new MatchingLinesOptions()); }
@Test(expected = AccessException.class) public void testGrepOptInfoAccessException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(AccessException.AccessExceptionForTests.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, null, new MatchingLinesOptions()); }
@Test(expected = RequestException.class) public void testGrepOptRequestException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(RequestException.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, new MatchingLinesOptions()); }
@Test(expected = RequestException.class) public void testGrepOptInfoRequestException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(RequestException.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, null, new MatchingLinesOptions()); }
@Test(expected = P4JavaException.class) public void testGrepOptP4JavaException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(P4JavaException.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, new MatchingLinesOptions()); }
@Test(expected = P4JavaException.class) public void testGrepOptInfoP4JavaException() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenThrow(P4JavaException.class); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); grepDelegator.getMatchingLines(specs, PATTERN, null, new MatchingLinesOptions()); }
@Test public void testGrepOpt() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenReturn(buildValidResultMap()); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); List<IFileLineMatch> matches = grepDelegator.getMatchingLines(specs, PATTERN, new MatchingLinesOptions()); assertMatches(matches); }
@Test public void testGrepOptInfo() throws P4JavaException { when(server.execMapCmdList(eq(GREP.toString()), argThat(GREP_FS_MATCHER), eq(null))) .thenReturn(buildValidResultMapWithInfo()); List<IServerMessage> infoLines = new ArrayList<>(); List<IFileSpec> specs = FileSpecBuilder.makeFileSpecList(CLIENT_FILE); List<IFileLineMatch> matches = grepDelegator.getMatchingLines(specs, PATTERN, infoLines, new MatchingLinesOptions()); assertMatches(matches); assertEquals(1, infoLines.size()); assertThat( infoLines.get(0), startsWithText(" }