blob: 1510df7bc7d81b17de63b16cca4223089061eae7 [file] [log] [blame]
samanwita pald1acfd82015-06-24 11:18:43 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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
Jordan Halterman71635ae2017-07-28 10:35:43 -070033 private final MapEvent<String, Integer> stats1 =
34 new MapEvent<>(MapEvent.Type.INSERT, "a", "1", vStatsNew, null);
samanwita pald1acfd82015-06-24 11:18:43 -070035
Jordan Halterman71635ae2017-07-28 10:35:43 -070036 private final MapEvent<String, Integer> stats2 =
37 new MapEvent<>(MapEvent.Type.REMOVE, "a", "1", null, vStatsOld);
samanwita pald1acfd82015-06-24 11:18:43 -070038
Jordan Halterman71635ae2017-07-28 10:35:43 -070039 private final MapEvent<String, Integer> stats3 =
40 new MapEvent<>(MapEvent.Type.UPDATE, "a", "1", vStatsNew, vStatsOld);
samanwita pald1acfd82015-06-24 11:18:43 -070041
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 Jampanif95290a2016-01-27 21:06:11 -080050 assertThat(stats1.value(), is(vStatsNew));
51 assertThat(stats1.newValue(), is(vStatsNew));
52 assertThat(stats1.oldValue(), is((Versioned<Integer>) null));
53
54 assertThat(stats2.name(), is("a"));
55 assertThat(stats2.type(), is(MapEvent.Type.REMOVE));
56 assertThat(stats2.key(), is("1"));
57 assertThat(stats2.value(), is(vStatsOld));
58 assertThat(stats2.newValue(), is((Versioned<Integer>) null));
59 assertThat(stats2.oldValue(), is(vStatsOld));
60
61 assertThat(stats3.name(), is("a"));
62 assertThat(stats3.type(), is(MapEvent.Type.UPDATE));
63 assertThat(stats3.key(), is("1"));
64 assertThat(stats3.value(), is(vStatsNew));
65 assertThat(stats3.newValue(), is(vStatsNew));
66 assertThat(stats3.oldValue(), is(vStatsOld));
samanwita pald1acfd82015-06-24 11:18:43 -070067 }
68
69 /**
70 * Tests the equals, hashCode and toString methods using Guava EqualsTester.
71 */
72 @Test
73 public void testEquals() {
74 new EqualsTester()
75 .addEqualityGroup(stats1, stats1)
76 .addEqualityGroup(stats2)
77 .addEqualityGroup(stats3)
78 .testEquals();
79 }
80
Sho SHIMIZU8dc81ea2015-09-10 10:59:43 -070081}