ChangeDelegator extends BaseDelegator implements IChangeDelegator { @Override public IChangelist getChangelist(final int id) throws ConnectionException, RequestException, AccessException { try { return getChangelist(id, null); } catch (final ConnectionException | RequestException | AccessException exc) { throw exc; } catch (P4JavaException exc) { throw new RequestException(exc.getMessage(), exc); } } ChangeDelegator(final IOptionsServer server); @Override IChangelist getChangelist(final int id); @Override String deletePendingChangelist(final int id); @Override String deletePendingChangelist(final int id, final ChangelistOptions opts); @Override IChangelist getChangelist(final int id, final ChangelistOptions opts);  }
@Test public void testGetChangelistAccessException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq(null))) .thenThrow(AccessException.AccessExceptionForTests.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("AccessException was expected."); } catch (AccessException accEx) { } catch (Exception ex) { fail("AccessException was expected."); } }
@Test public void testGetChangelistConnectionException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq((Map<String, Object>) null))).thenThrow(ConnectionException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("ConnectionException was expected."); } catch (ConnectionException conEx) { } catch (Exception ex) { fail("ConnectionException was expected."); } }
@Test public void testGetChangelistAccessException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq((Map<String, Object>) null))).thenThrow(AccessException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("AccessException was expected."); } catch (AccessException accEx) { } catch (Exception ex) { fail("AccessException was expected."); } }
@Test public void testGetChangelistRequestException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq((Map<String, Object>) null))).thenThrow(RequestException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("RequestException was expected."); } catch (RequestException reqEx) { } catch (Exception ex) { fail("RequestException was expected."); } }
@Test public void testGetChangelistP4JavaException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq((Map<String, Object>) null))).thenThrow(P4JavaException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("P4JavaException was expected."); } catch (P4JavaException p4Ex) { } catch (Exception ex) { fail("P4JavaException was expected."); } }
@Test public void testGetChangelistbyId() throws P4JavaException { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq((Map<String, Object>) null))).thenReturn(buildChangeList()); IChangelist changelist = changeDelegator.getChangelist(MOCK_LIST_ID); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq((Map<String, Object>) null)); assertEquals(MOCK_LIST_ID, changelist.getId()); }
@Test public void testGetChangelistbyDefaultId() throws P4JavaException { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(DEFAULT_ID_PARAMS_MATCHER), eq((Map<String, Object>) null))).thenReturn(buildChangeList()); changeDelegator.getChangelist(Changelist.DEFAULT); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(DEFAULT_ID_PARAMS_MATCHER), eq((Map<String, Object>) null)); }
@Test public void testGetChangelistbyIdAndOptions() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq((Map<String, Object>) null))).thenReturn(null); IChangelist cl = changeDelegator.getChangelist(MOCK_LIST_ID, mockChangelistOptions); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq((Map<String, Object>) null)); assertNull("Change list returned should have been null", cl); }
@Test public void testGetChangelistbyIdAndOptionsNull() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq((Map<String, Object>) null))).thenReturn(buildNullChangeList()); IChangelist cl = changeDelegator.getChangelist(MOCK_LIST_ID, mockChangelistOptions); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq((Map<String, Object>) null)); assertNull("Change list returned should have been null", cl); }
@Test public void testGetChangelistConnectionException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq(null))) .thenThrow(ConnectionException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("ConnectionException was expected."); } catch (ConnectionException conEx) { } catch (Exception ex) { fail("ConnectionException was expected."); } }
@Test public void testGetChangelistAccessException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq(null))) .thenThrow(AccessException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("AccessException was expected."); } catch (AccessException accEx) { } catch (Exception ex) { fail("AccessException was expected."); } }
@Test public void testGetChangelistRequestException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq(null))) .thenThrow(RequestException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("RequestException was expected."); } catch (RequestException reqEx) { } catch (Exception ex) { fail("RequestException was expected."); } }
@Test public void testGetChangelistP4JavaException() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), any(String[].class), eq(null))) .thenThrow(P4JavaException.class); try { changeDelegator.getChangelist(MOCK_LIST_ID); fail("P4JavaException was expected."); } catch (P4JavaException p4Ex) { } catch (Exception ex) { fail("P4JavaException was expected."); } }
@Test public void testGetChangelistbyId() throws P4JavaException { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq(null))) .thenReturn(buildChangeList()); IChangelist changelist = changeDelegator.getChangelist(MOCK_LIST_ID); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq(null)); assertEquals(MOCK_LIST_ID, changelist.getId()); }
@Test public void testGetChangelistbyDefaultId() throws P4JavaException { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(DEFAULT_ID_PARAMS_MATCHER), eq(null))).thenReturn(buildChangeList()); changeDelegator.getChangelist(Changelist.DEFAULT); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(DEFAULT_ID_PARAMS_MATCHER), eq(null)); }
@Test public void testGetChangelistbyIdAndOptions() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq(null))) .thenReturn(null); IChangelist cl = changeDelegator.getChangelist(MOCK_LIST_ID, mockChangelistOptions); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq(null)); assertNull(cl, "Change list returned should have been null"); }
@Test public void testGetChangelistbyIdAndOptionsNull() throws Exception { when(server.execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq(null))) .thenReturn(buildNullChangeList()); IChangelist cl = changeDelegator.getChangelist(MOCK_LIST_ID, mockChangelistOptions); verify(server).execMapCmdList(eq(CHANGE.toString()), argThat(GET_ID_PARAMS_MATCHER), eq(null)); assertNull(cl, "Change list returned should have been null"); }