Sho SHIMIZU | 9257b0c | 2014-08-13 15:00:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.newintent; |
| 2 | |
| 3 | import net.onrc.onos.api.newintent.IntentId; |
Sho SHIMIZU | fc932d5 | 2014-08-15 11:22:37 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.util.IdBlock; |
Sho SHIMIZU | 9257b0c | 2014-08-13 15:00:10 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.IdBlockAllocator; |
| 6 | import org.junit.Before; |
| 7 | import org.junit.Test; |
| 8 | |
| 9 | import static org.easymock.EasyMock.createMock; |
| 10 | import static org.easymock.EasyMock.expect; |
| 11 | import static org.easymock.EasyMock.replay; |
| 12 | import static org.hamcrest.Matchers.is; |
| 13 | import static org.junit.Assert.assertThat; |
| 14 | |
| 15 | /** |
| 16 | * Suites of test of {@link IdBlockAllocatorBasedIntentIdGenerator}. |
| 17 | */ |
| 18 | public class IdBlockAllocatorBasedIntentIdGeneratorTest { |
| 19 | private IdBlockAllocator allocator; |
| 20 | private IdBlockAllocatorBasedIntentIdGenerator sut; |
| 21 | |
| 22 | @Before |
| 23 | public void setUp() { |
| 24 | allocator = createMock(IdBlockAllocator.class); |
| 25 | |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Tests generated IntentId sequences using two {@link IdBlock blocks}. |
| 30 | */ |
| 31 | @Test |
| 32 | public void testIds() { |
| 33 | expect(allocator.allocateUniqueIdBlock()) |
| 34 | .andReturn(new IdBlock(0, 3)) |
| 35 | .andReturn(new IdBlock(4, 3)); |
| 36 | |
| 37 | replay(allocator); |
| 38 | sut = new IdBlockAllocatorBasedIntentIdGenerator(allocator); |
| 39 | |
| 40 | assertThat(sut.getNewId(), is(new IntentId(0))); |
| 41 | assertThat(sut.getNewId(), is(new IntentId(1))); |
| 42 | assertThat(sut.getNewId(), is(new IntentId(2))); |
| 43 | |
| 44 | assertThat(sut.getNewId(), is(new IntentId(4))); |
| 45 | assertThat(sut.getNewId(), is(new IntentId(5))); |
| 46 | assertThat(sut.getNewId(), is(new IntentId(6))); |
| 47 | } |
| 48 | } |