CounterDelegator extends BaseDelegator implements ICounterDelegator { @Override public String getCounter(final String counterName) throws ConnectionException, RequestException, AccessException { try { return getCounter(counterName, null); } catch (final ConnectionException | AccessException | RequestException exc) { throw exc; } catch (P4JavaException exc) { throw new RequestException(exc.getMessage(), exc); } } CounterDelegator(final IOptionsServer server); @Override String getCounter(final String counterName); @Override String getCounter(final String counterName, final CounterOptions opts); @Override void setCounter(final String counterName, final String value,
            final boolean perforceCounter); @Override String setCounter(final String counterName, final String value,
            final CounterOptions opts); @Override void deleteCounter(final String counterName, final boolean perforceCounter);  }
@Test public void getCounterCheckAccessException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenThrow(AccessException.AccessExceptionForTests.class); try { counterDelegator.getCounter(mockCounterName); } catch (AccessException e) { return; } fail("Did not return AccessException"); }
@SuppressWarnings("unchecked") @Test public void getCounterCheckConnectionException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), (Map<String, Object>) any())) .thenThrow(ConnectionException.class); try { counterDelegator.getCounter(mockCounterName); } catch (ConnectionException e) { return; } fail("Did not return ConnectionException"); }
@SuppressWarnings("unchecked") @Test public void getCounterCheckAccessException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), (Map<String, Object>) any())) .thenThrow(AccessException.class); try { counterDelegator.getCounter(mockCounterName); } catch (AccessException e) { return; } fail("Did not return AccessException"); }
@SuppressWarnings("unchecked") @Test public void getCounterCheckRequestException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), (Map<String, Object>) any())) .thenThrow(RequestException.class); try { counterDelegator.getCounter(mockCounterName); } catch (RequestException e) { return; } fail("Did not return RequestException"); }
@SuppressWarnings("unchecked") @Test public void getCounterCheckP4JavaException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), (Map<String, Object>) any())) .thenThrow(P4JavaException.class); try { counterDelegator.getCounter(mockCounterName); } catch (RequestException e) { return; } fail("Did not return RequestException"); }
@SuppressWarnings("unchecked") @Test public void getCounterReturnNonBlankCounterName() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("value", mockCounterValue); ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); list.add(map); when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), (Map<String, Object>) any())) .thenReturn(list); String counter = counterDelegator.getCounter(mockCounterName); assertThat(counter, is(mockCounterValue)); }
@Test public void getCounterWhenCounterNameIsBlank() throws Exception { try { counterDelegator.getCounter("", new CounterOptions()); } catch (IllegalArgumentException e) { return; } fail("Did not throw exception with blank counter name"); }
@SuppressWarnings("unchecked") @Test public void getCounterWithOptionsReturnNonBlankCounterName() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("value", mockCounterValue); ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); list.add(map); when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), (Map<String, Object>) any())) .thenReturn(list); String counter = counterDelegator.getCounter(mockCounterName, new CounterOptions()); assertThat(counter, is(mockCounterValue)); }
@Test public void getCounterCheckConnectionException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenThrow(ConnectionException.class); try { counterDelegator.getCounter(mockCounterName); } catch (ConnectionException e) { return; } fail("Did not return ConnectionException"); }
@Test public void getCounterCheckAccessException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenThrow(AccessException.class); try { counterDelegator.getCounter(mockCounterName); } catch (AccessException e) { return; } fail("Did not return AccessException"); }
@Test public void getCounterCheckRequestException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenThrow(RequestException.class); try { counterDelegator.getCounter(mockCounterName); } catch (RequestException e) { return; } fail("Did not return RequestException"); }
@Test public void getCounterCheckP4JavaException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenThrow(P4JavaException.class); try { counterDelegator.getCounter(mockCounterName); } catch (RequestException e) { return; } fail("Did not return RequestException"); }
@Test public void getCounterReturnNonBlankCounterName() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("value", mockCounterValue); ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); list.add(map); when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenReturn(list); String counter = counterDelegator.getCounter(mockCounterName); assertThat(counter, is(mockCounterValue)); }
@Test public void getCounterWhenCounterNameIsBlank() throws Exception { try { String counter = counterDelegator.getCounter("", new CounterOptions()); } catch (IllegalArgumentException e) { return; } fail("Did not throw exception with blank counter name"); }
@Test public void getCounterWithOptionsReturnNonBlankCounterName() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("value", mockCounterValue); ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); list.add(map); when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { mockCounterName }), any(null))) .thenReturn(list); String counter = counterDelegator.getCounter(mockCounterName, new CounterOptions()); assertThat(counter, is(mockCounterValue)); }