InterchangesDelegator extends BaseDelegator implements IInterchangesDelegator { public List<IChangelist> processInterchangeMaps(final List<Map<String, Object>> resultMaps, final boolean showFiles) throws ConnectionException, AccessException, RequestException { List<IChangelist> interchangeList = new ArrayList<>(); if (nonNull(resultMaps)) { for (Map<String, Object> map : resultMaps) { if (nonNull(map)) { String errStr = server.handleFileErrorStr(map); if (isNotBlank(errStr)) { if (server.getGenericCode(map) != 17 && server.getSeverityCode(map) != 2 && !contains(errStr, "all revision(s) already integrated")) { throw new RequestException(errStr, parseCode0ErrorString(map)); } } else { ChangelistSummary changelistSummary = new ChangelistSummary(map, true, server); Changelist changelist = new Changelist(changelistSummary, server, false); interchangeList.add(changelist); List<IFileSpec> fileSpecs = new ArrayList<IFileSpec>(); changelist.setFileSpecs(fileSpecs); if (showFiles) { int i = 0; while (nonNull(map.get(DEPOT_FILE + i))) { FileSpec fileSpec = new FileSpec(map, server, i); fileSpec.setChangelistId(changelist.getId()); fileSpecs.add(fileSpec); i++; } } } } } } return interchangeList; } InterchangesDelegator(IOptionsServer server); @Override List<IChangelist> getInterchanges(final IFileSpec fromFile, final IFileSpec toFile,
            final GetInterchangesOptions opts); @Override List<IChangelist> getInterchanges(final String branchSpecName,
            final List<IFileSpec> fromFileList, final List<IFileSpec> toFileList,
            final GetInterchangesOptions opts); List<IChangelist> getInterchanges(final IFileSpec fromFile, final IFileSpec toFile,
            final boolean showFiles, final boolean longDesc, final int maxChangelistId); List<IChangelist> getInterchanges(final String branchSpecName,
            final List<IFileSpec> fromFileList, final List<IFileSpec> toFileList,
            final boolean showFiles, final boolean longDesc, final int maxChangelistId,
            final boolean reverseMapping, final boolean biDirectional); List<IChangelist> processInterchangeMaps(final List<Map<String, Object>> resultMaps,
            final boolean showFiles);  }
@Test public void testNullResultMap() throws P4JavaException { when(server.execMapCmdList(eq(INTERCHANGES.toString()), argThat(new CommandLineArgumentMatcher(new String[0])), eq((Map<String, Object>) null))).thenReturn(null); when(server.execMapCmdList(eq(INTERCHANGES.toString()), any(String[].class), eq((Map<String, Object>) null))).thenReturn(null); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(null, true); assertNotNull(changelists); assertEquals(0, changelists.size()); }
@SuppressWarnings("deprecation") @Test public void testErrorMessageWithValidReturnCode() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn("error was occurred"); when(server.getGenericCode(resultMap)).thenReturn(17); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, true); assertNotNull(changelists); assertEquals(0, changelists.size()); }
@SuppressWarnings("deprecation") @Test public void testErrorMessageWithValidSeverityCode() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn("error was occurred"); when(server.getSeverityCode(resultMap)).thenReturn(2); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, true); assertNotNull(changelists); assertEquals(0, changelists.size()); }
@SuppressWarnings("deprecation") @Test public void testAlreadyIntegrated() throws P4JavaException { when(server.getGenericCode(resultMap)).thenReturn(17); when(server.getSeverityCode(resultMap)).thenReturn(2); when(server.handleFileErrorStr(resultMap)).thenReturn("all revision(s) already integrated"); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, true); assertNotNull(changelists); assertEquals(0, changelists.size()); }
@SuppressWarnings("deprecation") @Test(expected = RequestException.class) public void testServerErrorMessage() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn("error was occurred"); int isNot17 = 19; int isNot2 = 3; when(server.getGenericCode(resultMap)).thenReturn(isNot17); when(server.getSeverityCode(resultMap)).thenReturn(isNot2); interchangesDelegator.processInterchangeMaps(resultMaps, true); }
@SuppressWarnings("deprecation") @Test public void testEmptyErrorsResult() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn(EMPTY); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, false); assertEquals(1, changelists.size()); assertEquals(0, ((Changelist) changelists.get(0)).getFileSpecs().size()); }
@SuppressWarnings("deprecation") @Test public void testDepotFiles() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn(EMPTY); Object nonNullObj = new Object(); when(resultMap.get("depotFile0")).thenReturn(nonNullObj); when(resultMap.get("depotFile1")).thenReturn(nonNullObj); when(resultMap.get("depotFile2")).thenReturn(null); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, true); assertEquals(1, changelists.size()); assertEquals(2, ((Changelist) changelists.get(0)).getFileSpecs().size()); }
@Test public void testNullResultMap() throws P4JavaException { when(server.execMapCmdList(eq(INTERCHANGES.toString()), argThat(new CommandLineArgumentMatcher(new String[0])), eq(null))).thenReturn(null); when(server.execMapCmdList(eq(INTERCHANGES.toString()), any(String[].class), eq(null))) .thenReturn(null); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(null, true); assertNotNull(changelists); assertEquals(0, changelists.size()); }
@Test public void testServerErrorMessage() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn("error was occurred"); int isNot17 = 19; int isNot2 = 3; when(server.getGenericCode(resultMap)).thenReturn(isNot17); when(server.getSeverityCode(resultMap)).thenReturn(isNot2); expectThrows(RequestException.class, () -> interchangesDelegator.processInterchangeMaps(resultMaps, true)); }
@Test public void testEmptyErrorsResult() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn(EMPTY); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, false); assertEquals(1, changelists.size()); assertEquals(0, ((Changelist) changelists.get(0)).getFileSpecs().size()); }
@Test public void testDepotFiles() throws P4JavaException { when(server.handleFileErrorStr(resultMap)).thenReturn(EMPTY); Object nonNullObj = new Object(); when(resultMap.get("depotFile0")).thenReturn(nonNullObj); when(resultMap.get("depotFile1")).thenReturn(nonNullObj); when(resultMap.get("depotFile2")).thenReturn(null); List<IChangelist> changelists = interchangesDelegator.processInterchangeMaps(resultMaps, true); assertEquals(1, changelists.size()); assertEquals(2, ((Changelist) changelists.get(0)).getFileSpecs().size()); }