Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 1 | package org.onlab.onos.core.impl; |
| 2 | |
| 3 | import org.easymock.EasyMock; |
| 4 | import org.hamcrest.Matchers; |
| 5 | import org.junit.Assert; |
| 6 | import org.junit.Before; |
| 7 | import org.junit.Test; |
| 8 | import org.onlab.onos.core.IdBlock; |
| 9 | |
| 10 | /** |
| 11 | * Suites of test of {@link org.onlab.onos.core.impl.BlockAllocatorBasedIdGenerator}. |
| 12 | */ |
| 13 | public class IdBlockAllocatorBasedIdGeneratorTest { |
| 14 | private IdBlockAllocator allocator; |
| 15 | private BlockAllocatorBasedIdGenerator sut; |
| 16 | |
| 17 | @Before |
| 18 | public void setUp() { |
| 19 | allocator = EasyMock.createMock(IdBlockAllocator.class); |
| 20 | |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Tests generated IntentId sequences using two {@link org.onlab.onos.core.IdBlock blocks}. |
| 25 | */ |
| 26 | @Test |
| 27 | public void testIds() { |
| 28 | EasyMock.expect(allocator.allocateUniqueIdBlock()) |
| 29 | .andReturn(new IdBlock(0, 3)) |
| 30 | .andReturn(new IdBlock(4, 3)); |
| 31 | |
| 32 | EasyMock.replay(allocator); |
| 33 | sut = new BlockAllocatorBasedIdGenerator(allocator); |
| 34 | |
| 35 | Assert.assertThat(sut.getNewId(), Matchers.is(0L)); |
| 36 | Assert.assertThat(sut.getNewId(), Matchers.is(1L)); |
| 37 | Assert.assertThat(sut.getNewId(), Matchers.is(2L)); |
| 38 | |
| 39 | Assert.assertThat(sut.getNewId(), Matchers.is(4L)); |
| 40 | Assert.assertThat(sut.getNewId(), Matchers.is(5L)); |
| 41 | Assert.assertThat(sut.getNewId(), Matchers.is(6L)); |
| 42 | } |
| 43 | } |