From 15f0b88446699bdeaffaf20c42bb31950b50aacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Wed, 2 May 2012 12:52:21 +0200 Subject: Add CyclicCountDownLatch. (You may not want to use this.) --- .../com/orbekk/util/CyclicCountDownLatchTest.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 same/src/test/java/com/orbekk/util/CyclicCountDownLatchTest.java (limited to 'same/src/test') diff --git a/same/src/test/java/com/orbekk/util/CyclicCountDownLatchTest.java b/same/src/test/java/com/orbekk/util/CyclicCountDownLatchTest.java new file mode 100644 index 0000000..769b7e5 --- /dev/null +++ b/same/src/test/java/com/orbekk/util/CyclicCountDownLatchTest.java @@ -0,0 +1,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)); + } +} -- cgit v1.2.3