blob: 646d0557ddb639b47906130a18134e3449718e41 [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.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 Jampanif95290a2016-01-27 21:06:11 -080056 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 Jampanif95290a2016-01-27 21:06:11 -080062 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}