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