summaryrefslogtreecommitdiff
path: root/same/src/test/java/com/orbekk/util/CyclicCountDownLatchTest.java
blob: 769b7e5ca8a5a5a9a20eb8d948f7d73390fb11eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.orbekk.util;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import org.junit.Test;

public class CyclicCountDownLatchTest {
    CyclicCountDownLatch latch = new CyclicCountDownLatch(1);

    @Test public void initialCount() {
        assertThat(latch.getCount(), is(1));
    }
    
    @Test public void releasesCorrectly() throws Exception {
        latch.countDown();
        assertThat(latch.getCount(), is(0));
        latch.await();
    }
    
    @Test public void testCycle() throws Exception {
        latch.countDown();
        latch.await();
        assertThat(latch.getCount(), is(1));
        latch.countDown();
        latch.await();
    }
    
    @Test public void notAccumulative() throws Exception {
        latch.countDown();
        latch.countDown();
        latch.await();
        assertThat(latch.getCount(), is(1));
    }
}