blob: 5cc89d85cbfa6f61b02f65d48fab42205b815856 [file] [log] [blame]
Ray Milkey67d53cc2015-07-23 16:32:36 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
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.SetEvent.Type.ADD;
26import static org.onosproject.store.service.SetEvent.Type.REMOVE;
27
28/**
29 * Unit tests for the SetEvent class.
30 */
31public class SetEventTest {
32
33 SetEvent<String> event1 =
34 new SetEvent<>("map1", ADD, "e1");
35 SetEvent<String> event2 =
36 new SetEvent<>("map1", REMOVE, "e1");
37 SetEvent<String> sameAsEvent2 =
38 new SetEvent<>("map1", REMOVE, "e1");
39 SetEvent<String> event3 =
40 new SetEvent<>("map1", ADD, "e2");
41 SetEvent<String> event4 =
42 new SetEvent<>("map1", REMOVE, "e2");
43
44 /**
45 * Checks that the SetEvent class is immutable.
46 */
47 @Test
48 public void testImmutability() {
49 assertThatClassIsImmutable(EventuallyConsistentMapEvent.class);
50 }
51
52 /**
53 * Checks the equals(), hashCode() and toString() operations.
54 */
55 @Test
56 public void testEquals() {
57 new EqualsTester()
58 .addEqualityGroup(event1)
59 .addEqualityGroup(event2, sameAsEvent2)
60 .addEqualityGroup(event3)
61 .addEqualityGroup(event4)
62 .testEquals();
63 }
64
65 /**
66 * Checks that construction of the object is correct.
67 */
68 @Test
69 public void testConstruction() {
70 assertThat(event1.type(), is(ADD));
71 assertThat(event1.entry(), is("e1"));
72 assertThat(event1.name(), is("map1"));
73 }
74
75}