/*
 * Copyright 2016 Timothy Brooks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package net.uncontended.precipice;

import org.junit.Before;

public class ControllerTest {

    private Controller<Status> controller;

    @Before
    public void setup() {
        ControllerProperties<Status> properties = new ControllerProperties<>(Status.class);
        controller = new Controller<Status>("Controller Name", properties);

    }

}

@@ -638,24 +638,320 @@
 ort 
-org.junit.Before
+net.uncontended.precipice.circuit.CircuitBreaker;%0Aimport net.uncontended.precipice.concurrent.IntegerSemaphore;%0Aimport net.uncontended.precipice.concurrent.PrecipiceSemaphore;%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.*;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when
 ;%0A%0Ap
@@ -1033,14 +1033,12 @@
    @
-Before
+Test
 %0A   
@@ -1054,13 +1054,50 @@
 oid 
-setup
+capacityAndPendingCallsDelegateToSemaphore
 () %7B
@@ -1189,16 +1189,72 @@
 class);%0A
+        properties.semaphore(new IntegerSemaphore(10));%0A
         
@@ -1322,16 +1322,1380 @@
 ties);%0A%0A
+        assertEquals(10, controller.remainingCapacity());%0A        assertEquals(0, controller.pendingCount());%0A%0A        controller.acquirePermitOrGetRejectedReason();%0A%0A        assertEquals(9, controller.remainingCapacity());%0A        assertEquals(1, controller.pendingCount());%0A    %7D%0A%0A    @Test%0A    public void acquirePermitOrGetRejectedReasonReturnsMaxConcurrency() %7B%0A        CircuitBreaker breaker = mock(CircuitBreaker.class);%0A        PrecipiceSemaphore semaphore = mock(PrecipiceSemaphore.class);%0A%0A        ControllerProperties%3CStatus%3E properties = new ControllerProperties%3C%3E(Status.class);%0A        properties.circuitBreaker(breaker);%0A        properties.semaphore(semaphore);%0A        controller = new Controller%3CStatus%3E(%22Controller Name%22, properties);%0A%0A        when(semaphore.acquirePermit()).thenReturn(true);%0A        when(breaker.allowAction()).thenReturn(true);%0A%0A        assertNull(controller.acquirePermitOrGetRejectedReason());%0A%0A        when(semaphore.acquirePermit()).thenReturn(false);%0A        when(breaker.allowAction()).thenReturn(true);%0A%0A        assertSame(Rejected.MAX_CONCURRENCY_LEVEL_EXCEEDED, controller.acquirePermitOrGetRejectedReason());%0A%0A        when(semaphore.acquirePermit()).thenReturn(true);%0A        when(breaker.allowAction()).thenReturn(false);%0A%0A        assertSame(Rejected.CIRCUIT_OPEN, controller.acquirePermitOrGetRejectedReason());%0A%0A%0A
     %7D%0A%0A%7D

Work on implementing new controller tests