CounterStoreConnector implements Connector { public Integer get(String name) throws IllegalStateException { if (!countersMap.containsKey(name)) { throw new IllegalStateException("Undefined counter: " + name); } return countersMap.get(name); } CounterStoreConnector(CounterDAO counterDAO, User user, Project project, List<Counter> counterList); @Override void reset(); @Override void dispose(); @Override void post(); void set(Long projectId, String name, Integer value); void incrementBy(Long projectId, String name, int incrementBy); Integer get(String name); boolean contains(String name); Map<String, Integer> getStore(); CounterStoreConnector copy();  }
@Test public void shouldInitializeTheInternalStoreCorrectly() { Counter c1 = new Counter(); c1.setName("c1"); c1.setValue(3); Counter c2 = new Counter(); c2.setName("c2"); c1.setValue(4); List<Counter> counters = new ArrayList<>(Arrays.asList(c1, c2)); CounterStoreConnector connector = new CounterStoreConnector(mock(CounterDAO.class), mock(User.class), mock(Project.class), counters); assertEquals(connector.get(c1.getName()), c1.getValue()); assertEquals(connector.get(c2.getName()), c2.getValue()); }
@Test(expected = IllegalStateException.class) public void shouldFailToGetTheCounterIfNotDefined() { connector.get(COUNTER_NAME); }