blob: 07d30ca885af73f2e32d11fe23f2851d0f093115 [file] [log] [blame]
Brian O'Connor520c0522014-11-23 23:50:47 -08001package org.onlab.onos.core.impl;
2
3import org.easymock.EasyMock;
4import org.hamcrest.Matchers;
5import org.junit.Assert;
6import org.junit.Before;
7import org.junit.Test;
8import org.onlab.onos.core.IdBlock;
9
10/**
11 * Suites of test of {@link org.onlab.onos.core.impl.BlockAllocatorBasedIdGenerator}.
12 */
13public 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}