blob: f0fdcbf3a596937b96864cfbff8c44cd94a0bfb4 [file] [log] [blame]
Brian O'Connorabafb502014-12-02 22:26:20 -08001package org.onosproject.core.impl;
Brian O'Connor520c0522014-11-23 23:50:47 -08002
3import org.easymock.EasyMock;
4import org.hamcrest.Matchers;
5import org.junit.Assert;
6import org.junit.Before;
7import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -08008import org.onosproject.core.IdBlock;
Brian O'Connor520c0522014-11-23 23:50:47 -08009
10/**
Brian O'Connorabafb502014-12-02 22:26:20 -080011 * Suites of test of {@link org.onosproject.core.impl.BlockAllocatorBasedIdGenerator}.
Brian O'Connor520c0522014-11-23 23:50:47 -080012 */
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 /**
Brian O'Connorabafb502014-12-02 22:26:20 -080024 * Tests generated IntentId sequences using two {@link org.onosproject.core.IdBlock blocks}.
Brian O'Connor520c0522014-11-23 23:50:47 -080025 */
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}