samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
Madan Jampani | f95290a | 2016-01-27 21:06:11 -0800 | [diff] [blame] | 19 | |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | |
| 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | |
| 25 | /** |
| 26 | * MapEvent unit tests. |
| 27 | */ |
Sho SHIMIZU | 8dc81ea | 2015-09-10 10:59:43 -0700 | [diff] [blame] | 28 | public class MapEventTest { |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 29 | |
Madan Jampani | f95290a | 2016-01-27 21:06:11 -0800 | [diff] [blame] | 30 | private final Versioned<Integer> vStatsNew = new Versioned<>(2, 2); |
| 31 | private final Versioned<Integer> vStatsOld = new Versioned<>(1, 1); |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 32 | |
Jordan Halterman | 71635ae | 2017-07-28 10:35:43 -0700 | [diff] [blame] | 33 | private final MapEvent<String, Integer> stats1 = |
| 34 | new MapEvent<>(MapEvent.Type.INSERT, "a", "1", vStatsNew, null); |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 35 | |
Jordan Halterman | 71635ae | 2017-07-28 10:35:43 -0700 | [diff] [blame] | 36 | private final MapEvent<String, Integer> stats2 = |
| 37 | new MapEvent<>(MapEvent.Type.REMOVE, "a", "1", null, vStatsOld); |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 38 | |
Jordan Halterman | 71635ae | 2017-07-28 10:35:43 -0700 | [diff] [blame] | 39 | private final MapEvent<String, Integer> stats3 = |
| 40 | new MapEvent<>(MapEvent.Type.UPDATE, "a", "1", vStatsNew, vStatsOld); |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Tests the creation of the MapEvent object. |
| 44 | */ |
| 45 | @Test |
| 46 | public void testConstruction() { |
| 47 | assertThat(stats1.name(), is("a")); |
| 48 | assertThat(stats1.type(), is(MapEvent.Type.INSERT)); |
| 49 | assertThat(stats1.key(), is("1")); |
Madan Jampani | f95290a | 2016-01-27 21:06:11 -0800 | [diff] [blame] | 50 | assertThat(stats1.newValue(), is(vStatsNew)); |
| 51 | assertThat(stats1.oldValue(), is((Versioned<Integer>) null)); |
| 52 | |
| 53 | assertThat(stats2.name(), is("a")); |
| 54 | assertThat(stats2.type(), is(MapEvent.Type.REMOVE)); |
| 55 | assertThat(stats2.key(), is("1")); |
Madan Jampani | f95290a | 2016-01-27 21:06:11 -0800 | [diff] [blame] | 56 | assertThat(stats2.newValue(), is((Versioned<Integer>) null)); |
| 57 | assertThat(stats2.oldValue(), is(vStatsOld)); |
| 58 | |
| 59 | assertThat(stats3.name(), is("a")); |
| 60 | assertThat(stats3.type(), is(MapEvent.Type.UPDATE)); |
| 61 | assertThat(stats3.key(), is("1")); |
Madan Jampani | f95290a | 2016-01-27 21:06:11 -0800 | [diff] [blame] | 62 | assertThat(stats3.newValue(), is(vStatsNew)); |
| 63 | assertThat(stats3.oldValue(), is(vStatsOld)); |
samanwita pal | d1acfd8 | 2015-06-24 11:18:43 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Tests the equals, hashCode and toString methods using Guava EqualsTester. |
| 68 | */ |
| 69 | @Test |
| 70 | public void testEquals() { |
| 71 | new EqualsTester() |
| 72 | .addEqualityGroup(stats1, stats1) |
| 73 | .addEqualityGroup(stats2) |
| 74 | .addEqualityGroup(stats3) |
| 75 | .testEquals(); |
| 76 | } |
| 77 | |
Sho SHIMIZU | 8dc81ea | 2015-09-10 10:59:43 -0700 | [diff] [blame] | 78 | } |