blob: 698498e1f25895367955752c68a5757e2a6bb206 [file] [log] [blame]
samanwita pald1acfd82015-06-24 11:18:43 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
samanwita pald1acfd82015-06-24 11:18:43 -07003 *
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 */
16package org.onosproject.store.service;
17
18import com.google.common.testing.EqualsTester;
Madan Jampanif95290a2016-01-27 21:06:11 -080019
samanwita pald1acfd82015-06-24 11:18:43 -070020import org.junit.Test;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24
25/**
26 * MapEvent unit tests.
27 */
Sho SHIMIZU8dc81ea2015-09-10 10:59:43 -070028public class MapEventTest {
samanwita pald1acfd82015-06-24 11:18:43 -070029
Madan Jampanif95290a2016-01-27 21:06:11 -080030 private final Versioned<Integer> vStatsNew = new Versioned<>(2, 2);
31 private final Versioned<Integer> vStatsOld = new Versioned<>(1, 1);
samanwita pald1acfd82015-06-24 11:18:43 -070032
Madan Jampanif95290a2016-01-27 21:06:11 -080033 private final MapEvent<String, Integer> stats1 = new MapEvent<>("a", "1", vStatsNew, null);
samanwita pald1acfd82015-06-24 11:18:43 -070034
Madan Jampanif95290a2016-01-27 21:06:11 -080035 private final MapEvent<String, Integer> stats2 = new MapEvent<>("a", "1", null, vStatsOld);
samanwita pald1acfd82015-06-24 11:18:43 -070036
Madan Jampanif95290a2016-01-27 21:06:11 -080037 private final MapEvent<String, Integer> stats3 = new MapEvent<>("a", "1", vStatsNew, vStatsOld);
samanwita pald1acfd82015-06-24 11:18:43 -070038
39 /**
40 * Tests the creation of the MapEvent object.
41 */
42 @Test
43 public void testConstruction() {
44 assertThat(stats1.name(), is("a"));
45 assertThat(stats1.type(), is(MapEvent.Type.INSERT));
46 assertThat(stats1.key(), is("1"));
Madan Jampanif95290a2016-01-27 21:06:11 -080047 assertThat(stats1.value(), is(vStatsNew));
48 assertThat(stats1.newValue(), is(vStatsNew));
49 assertThat(stats1.oldValue(), is((Versioned<Integer>) null));
50
51 assertThat(stats2.name(), is("a"));
52 assertThat(stats2.type(), is(MapEvent.Type.REMOVE));
53 assertThat(stats2.key(), is("1"));
54 assertThat(stats2.value(), is(vStatsOld));
55 assertThat(stats2.newValue(), is((Versioned<Integer>) null));
56 assertThat(stats2.oldValue(), is(vStatsOld));
57
58 assertThat(stats3.name(), is("a"));
59 assertThat(stats3.type(), is(MapEvent.Type.UPDATE));
60 assertThat(stats3.key(), is("1"));
61 assertThat(stats3.value(), is(vStatsNew));
62 assertThat(stats3.newValue(), is(vStatsNew));
63 assertThat(stats3.oldValue(), is(vStatsOld));
samanwita pald1acfd82015-06-24 11:18:43 -070064 }
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 SHIMIZU8dc81ea2015-09-10 10:59:43 -070078}