1 package net.secodo.jcircuitbreaker.breakstrategy.impl;
2
3 import net.secodo.jcircuitbreaker.breaker.execution.ExecutedTask;
4 import net.secodo.jcircuitbreaker.breaker.execution.ExecutionContext;
5 import net.secodo.jcircuitbreaker.task.Task;
6 import org.junit.Test;
7
8 import java.util.ArrayList;
9
10 import static org.hamcrest.CoreMatchers.is;
11 import static org.junit.Assert.*;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.when;
14
15 public class SingleExecutionAllowedStrategyTest {
16
17 @Test
18 public void shouldNotAllowExecutionIfThereIsAnotherInProgress() {
19
20 SingleExecutionAllowedStrategy<Integer> breakStrategy = new SingleExecutionAllowedStrategy<>();
21 ExecutionContext<Integer> executionContext = mock(ExecutionContext.class);
22
23 ArrayList<ExecutedTask<Integer>> executedTasks = new ArrayList<ExecutedTask<Integer>>() {{ add(mock(ExecutedTask.class)); }};
24 when(executionContext.getExecutionsInProgress()).thenReturn(executedTasks);
25
26
27 boolean shouldBreak = breakStrategy.shouldBreak(mock(Task.class), executionContext);
28
29
30 assertThat(shouldBreak, is(true));
31
32 }
33
34
35 }