### Question:
TokenOperationsStore { public void addTokenOperation(TokenType type, CTSOperation operation, boolean success) { OperationStore operationStoreForTokenType = tokenOperations.get(type); if (operationStoreForTokenType == null) { operationStoreForTokenType = operationStoreFactory.createOperationStore(); tokenOperations.put(type, operationStoreForTokenType); } operationStoreForTokenType.add(operation); addTokenOperation(operation, success); } TokenOperationsStore();   TokenOperationsStore(final OperationStoreFactory operationStoreFactory,
            final Map<TokenType, OperationStore> tokenOperations,
            final OperationStore operationStore,
            final OperationStore operationFailureStore); void addTokenOperation(TokenType type, CTSOperation operation, boolean success); void addTokenOperation(CTSOperation operation, boolean success); double getAverageOperationsPerPeriod(TokenType type, CTSOperation operation); long getMinimumOperationsPerPeriod(TokenType type, CTSOperation operation); long getMaximumOperationsPerPeriod(TokenType type, CTSOperation operation); double getAverageOperationsPerPeriod(CTSOperation operation); double getAverageOperationFailuresPerPeriod(CTSOperation operation); long getMinimumOperationsPerPeriod(CTSOperation operation); long getMinimumOperationFailuresPerPeriod(CTSOperation operation); long getMaximumOperationsPerPeriod(CTSOperation operation); long getMaximumOperationFailuresPerPeriod(CTSOperation operation); long getOperationsCumulativeCount(TokenType type, CTSOperation operation); long getOperationsCumulativeCount(CTSOperation operation); long getOperationFailuresCumulativeCount(CTSOperation operation);  }### Answer:
@Test public void shouldAddTokenOperationForSpecificTokenType() { TokenType tokenType = TokenType.OAUTH; CTSOperation operation = CTSOperation.CREATE; OperationStore typeOperationStore = mock(OperationStore.class); given(operationStoreFactory.createOperationStore()).willReturn(typeOperationStore); tokenOperationsStore.addTokenOperation(tokenType, operation, true); assertTrue(tokenOperations.containsKey(TokenType.OAUTH)); verify(typeOperationStore).add(operation); }
@Test public void shouldAddTokenOperationForSpecificTokenTypeToExistingOperationStore() { TokenType tokenType = TokenType.OAUTH; CTSOperation operation = CTSOperation.CREATE; OperationStore typeOperationStore = mock(OperationStore.class); tokenOperations.put(TokenType.OAUTH, typeOperationStore); tokenOperationsStore.addTokenOperation(tokenType, operation, true); verifyZeroInteractions(operationStoreFactory); verify(typeOperationStore).add(operation); }
@Test public void shouldAddTokenOperationForSpecificTokenTypeUsingDefaultOperationStoreFactory() { TokenOperationsStore.OperationStoreFactory operationStoreFactory = new TokenOperationsStore.OperationStoreFactory(); TokenOperationsStore localTokenOperationsStore = new TokenOperationsStore(operationStoreFactory, tokenOperations, operationStore, operationFailureStore); TokenType tokenType = TokenType.OAUTH; CTSOperation operation = CTSOperation.CREATE; localTokenOperationsStore.addTokenOperation(tokenType, operation, true); assertTrue(tokenOperations.containsKey(TokenType.OAUTH)); }
@Test public void shouldAddTokenOperation() { CTSOperation operation = CTSOperation.CREATE; tokenOperationsStore.addTokenOperation(operation, true); verify(operationStore).add(operation); }