CountersDelegator extends BaseDelegator implements ICountersDelegator { @Override public Map<String, String> getCounters() throws ConnectionException, RequestException, AccessException { try { return getCounters(new GetCountersOptions()); } catch (final ConnectionException | AccessException | RequestException exc) { throw exc; } catch (P4JavaException exc) { throw new RequestException(exc.getMessage(), exc); } } CountersDelegator(IOptionsServer server); @Override Map<String, String> getCounters(); @Override Map<String, String> getCounters(final CounterOptions opts); @Override Map<String, String> getCounters(final GetCountersOptions opts);  }
@Test public void testGetCountersWithCounterOptions() throws P4JavaException { String mockValue = "mockValue"; String mockName = "counter"; when(server.execMapCmdList(eq(COUNTERS.toString()), argThat(new CommandLineArgumentMatcher(new String[] {})), eq((Map<String, Object>) null))).thenReturn(resultMaps); when(resultMap.get(VALUE)).thenReturn(mockValue); when(resultMap.get("counter")).thenReturn(mockName); Map<String, String> counters = countersDelegator.getCounters(new CounterOptions()); assertThat(counters.size(), is(1)); assertThat(counters.get(mockName), is(mockValue)); }
@Test public void testGetCounters() throws P4JavaException { String mockValue = "mockValue"; String mockName = "counter"; when(server.execMapCmdList(eq(COUNTERS.toString()), argThat(new CommandLineArgumentMatcher(new String[] {})), eq((Map<String, Object>) null))).thenReturn(resultMaps); when(resultMap.get(VALUE)).thenReturn(mockValue); when(resultMap.get("counter")).thenReturn(mockName); Map<String, String> counters = countersDelegator.getCounters(); assertThat(counters.size(), is(1)); assertThat(counters.get(mockName), is(mockValue)); }
@Test public void testGetCountersWithCounterOptions() throws P4JavaException { String mockValue = "mockValue"; String mockName = "counter"; when(server.execMapCmdList(eq(COUNTERS.toString()), argThat(new CommandLineArgumentMatcher(new String[] {})), eq(null))) .thenReturn(resultMaps); when(resultMap.get(VALUE)).thenReturn(mockValue); when(resultMap.get("counter")).thenReturn(mockName); Map<String, String> counters = countersDelegator.getCounters(new CounterOptions()); assertThat(counters.size(), is(1)); assertThat(counters.get(mockName), is(mockValue)); }
@Test public void testGetCounters() throws P4JavaException { String mockValue = "mockValue"; String mockName = "counter"; when(server.execMapCmdList(eq(COUNTERS.toString()), argThat(new CommandLineArgumentMatcher(new String[] {})), eq(null))) .thenReturn(resultMaps); when(resultMap.get(VALUE)).thenReturn(mockValue); when(resultMap.get("counter")).thenReturn(mockName); Map<String, String> counters = countersDelegator.getCounters(); assertThat(counters.size(), is(1)); assertThat(counters.get(mockName), is(mockValue)); }