Sho SHIMIZU | 9257b0c | 2014-08-13 15:00:10 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.core.registry; |
| 2 | |
| 3 | import net.onrc.onos.core.util.UnavailableIdException; |
| 4 | import org.junit.Test; |
| 5 | |
| 6 | import static org.hamcrest.Matchers.is; |
| 7 | import static org.junit.Assert.*; |
| 8 | |
| 9 | /** |
| 10 | * Suites of test of {@link IdBlock}. |
| 11 | */ |
| 12 | public class IdBlockTest { |
| 13 | |
| 14 | private final IdBlock sut = new IdBlock(0, 3); |
| 15 | |
| 16 | /** |
| 17 | * Tests generated sequences. Also checks occurrence of {@link UnavailableIdException}, |
| 18 | * when the number of generated IDs exceeds the block size. |
| 19 | */ |
| 20 | @Test |
| 21 | public void basics() { |
| 22 | assertThat(sut.getNextId(), is(0L)); |
| 23 | assertThat(sut.getNextId(), is(1L)); |
| 24 | assertThat(sut.getNextId(), is(2L)); |
| 25 | |
| 26 | try { |
| 27 | sut.getNextId(); |
| 28 | fail("UnavailableIdException should be thrown"); |
| 29 | } catch (UnavailableIdException e) { |
| 30 | assertTrue(true); |
| 31 | } |
| 32 | } |
| 33 | } |