blob: 255af079e498d53a31acfc8c35433be05fc81353 [file] [log] [blame]
Ray Milkeyd083bc42015-07-22 16:34:22 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyd083bc42015-07-22 16:34:22 -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 org.junit.Test;
19
20import com.google.common.testing.EqualsTester;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
26import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
27
28/**
29 * Unit tests for the EventuallyConsistentMapEvent class.
30 */
31public class EventuallyConsistentMapEventTest {
32
33 EventuallyConsistentMapEvent<String, String> event1 =
34 new EventuallyConsistentMapEvent<>("map1", PUT, "k1", "v1");
35 EventuallyConsistentMapEvent<String, String> event2 =
36 new EventuallyConsistentMapEvent<>("map1", REMOVE, "k1", "v1");
37 EventuallyConsistentMapEvent<String, String> sameAsEvent2 =
38 new EventuallyConsistentMapEvent<>("map1", REMOVE, "k1", "v1");
39 EventuallyConsistentMapEvent<String, String> event3 =
40 new EventuallyConsistentMapEvent<>("map1", PUT, "k2", "v1");
41 EventuallyConsistentMapEvent<String, String> event4 =
42 new EventuallyConsistentMapEvent<>("map1", PUT, "k1", "v2");
43 EventuallyConsistentMapEvent<String, String> event5 =
44 new EventuallyConsistentMapEvent<>("map2", REMOVE, "k1", "v2");
Ray Milkey92ea9b32015-07-24 09:28:09 -070045 EventuallyConsistentMapEvent<String, String> event6 =
46 new EventuallyConsistentMapEvent<>("map3", REMOVE, "k1", "v2");
47
Ray Milkeyd083bc42015-07-22 16:34:22 -070048
49 /**
50 * Checks the equals(), hashCode() and toString() operations.
51 */
52 @Test
53 public void testEquals() {
54 new EqualsTester()
55 .addEqualityGroup(event1)
56 .addEqualityGroup(event2, sameAsEvent2)
57 .addEqualityGroup(event3)
58 .addEqualityGroup(event4)
59 .addEqualityGroup(event5)
Ray Milkey92ea9b32015-07-24 09:28:09 -070060 .addEqualityGroup(event6)
Ray Milkeyd083bc42015-07-22 16:34:22 -070061 .testEquals();
62 }
63
64 /**
65 * Checks that the EventuallyConsistentMapEvent class is immutable.
66 */
67 @Test
68 public void testImmutability() {
69 assertThatClassIsImmutable(EventuallyConsistentMapEvent.class);
70 }
71
72 /**
73 * Checks that construction of the object is correct.
74 */
75 @Test
76 public void testConstruction() {
77 assertThat(event1.type(), is(PUT));
78 assertThat(event1.key(), is("k1"));
79 assertThat(event1.value(), is("v1"));
80 assertThat(event1.name(), is("map1"));
81 }
82}