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