CounterDelegator extends BaseDelegator implements ICounterDelegator { @Override public void deleteCounter(final String counterName, final boolean perforceCounter) throws ConnectionException, RequestException, AccessException { Validate.notBlank(counterName, "Counter name shouldn't null or empty"); try { CounterOptions counterOptions = new CounterOptions(perforceCounter, true, false); setCounter(counterName, null, counterOptions); } 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 deleteCounterCheckConnectionException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq((Map<String, Object>) null))) .thenThrow(ConnectionException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (ConnectionException e) { return; } catch (Throwable e) { } fail("Did not throw ConnectionException"); }
@Test public void deleteCounterCheckAccessException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq((Map<String, Object>) null))) .thenThrow(AccessException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (AccessException e) { return; } catch (Throwable e) { } fail("Did not throw AccessException"); }
@Test public void deleteCounterCheckRequestException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq((Map<String, Object>) null))) .thenThrow(RequestException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (RequestException e) { return; } catch (Throwable e) { } fail("Did not throw RequestException"); }
@Test public void deleteCounterCheckRequestExceptionWhenP4JavaException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq((Map<String, Object>) null))) .thenThrow(P4JavaException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (RequestException e) { return; } catch (Throwable e) { } fail("Did not throw RequestException"); }
@SuppressWarnings("unchecked") @Test public void deleteCounter() 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(any(String.class), any(String[].class), (Map<String, Object>) any(Map.class))).thenReturn(list); counterDelegator.deleteCounter(mockCounterName, true); String[] args = new String[] { "-f", "-d", mockCounterName }; verify(server).execMapCmdList(eq("counter"), eq(args), eq((Map<String, Object>) null)); }
@Test public void deleteCounterCheckIllegalArgument() throws Exception { try { counterDelegator.deleteCounter("", true); } catch (IllegalArgumentException e) { return; } catch (Throwable e) { } fail("Delete with blank name did not return IllegalArgumentException"); }
@Test public void deleteCounterCheckConnectionException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq(null))) .thenThrow(ConnectionException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (ConnectionException e) { return; } catch (Throwable e) { } fail("Did not throw ConnectionException"); }
@Test public void deleteCounterCheckAccessException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq(null))) .thenThrow(AccessException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (AccessException e) { return; } catch (Throwable e) { } fail("Did not throw AccessException"); }
@Test public void deleteCounterCheckRequestException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq(null))) .thenThrow(RequestException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (RequestException e) { return; } catch (Throwable e) { } fail("Did not throw RequestException"); }
@Test public void deleteCounterCheckRequestExceptionWhenP4JavaException() throws Exception { when(server.execMapCmdList(eq(CmdSpec.COUNTER.toString()), eq(new String[] { "-f", "-d", mockCounterName }), eq(null))) .thenThrow(P4JavaException.class); try { counterDelegator.deleteCounter(mockCounterName, true); } catch (RequestException e) { return; } catch (Throwable e) { } fail("Did not throw RequestException"); }
@Test public void deleteCounter() 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(any(String.class), any(String[].class), any(Map.class))) .thenReturn(list); counterDelegator.deleteCounter(mockCounterName, true); String[] args = new String[] { "-f", "-d", mockCounterName }; verify(server).execMapCmdList(eq("counter"), eq(args), eq(null)); }