Ray Milkey

Unit tests for AtomicValueEvent and SetEvent

Change-Id: I44562365f3076b7cc1afaf5cef9e5be584b432e9
...@@ -24,7 +24,7 @@ import com.google.common.base.MoreObjects; ...@@ -24,7 +24,7 @@ import com.google.common.base.MoreObjects;
24 * 24 *
25 * @param <V> atomic value type 25 * @param <V> atomic value type
26 */ 26 */
27 -public class AtomicValueEvent<V> { 27 +public final class AtomicValueEvent<V> {
28 28
29 /** 29 /**
30 * AtomicValueEvent type. 30 * AtomicValueEvent type.
...@@ -87,7 +87,7 @@ public class AtomicValueEvent<V> { ...@@ -87,7 +87,7 @@ public class AtomicValueEvent<V> {
87 return false; 87 return false;
88 } 88 }
89 89
90 - AtomicValueEvent<V> that = (AtomicValueEvent) o; 90 + AtomicValueEvent that = (AtomicValueEvent) o;
91 return Objects.equals(this.name, that.name) && 91 return Objects.equals(this.name, that.name) &&
92 Objects.equals(this.type, that.type) && 92 Objects.equals(this.type, that.type) &&
93 Objects.equals(this.value, that.value); 93 Objects.equals(this.value, that.value);
...@@ -106,4 +106,4 @@ public class AtomicValueEvent<V> { ...@@ -106,4 +106,4 @@ public class AtomicValueEvent<V> {
106 .add("value", value) 106 .add("value", value)
107 .toString(); 107 .toString();
108 } 108 }
109 -}
...\ No newline at end of file ...\ No newline at end of file
109 +}
......
...@@ -24,7 +24,7 @@ import com.google.common.base.MoreObjects; ...@@ -24,7 +24,7 @@ import com.google.common.base.MoreObjects;
24 * 24 *
25 * @param <E> set element type 25 * @param <E> set element type
26 */ 26 */
27 -public class SetEvent<E> { 27 +public final class SetEvent<E> {
28 28
29 /** 29 /**
30 * SetEvent type. 30 * SetEvent type.
...@@ -91,7 +91,7 @@ public class SetEvent<E> { ...@@ -91,7 +91,7 @@ public class SetEvent<E> {
91 return false; 91 return false;
92 } 92 }
93 93
94 - SetEvent<E> that = (SetEvent) o; 94 + SetEvent that = (SetEvent) o;
95 return Objects.equals(this.name, that.name) && 95 return Objects.equals(this.name, that.name) &&
96 Objects.equals(this.type, that.type) && 96 Objects.equals(this.type, that.type) &&
97 Objects.equals(this.entry, that.entry); 97 Objects.equals(this.entry, that.entry);
......
1 +/*
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 + */
16 +package org.onosproject.store.service;
17 +
18 +import org.junit.Test;
19 +
20 +import com.google.common.testing.EqualsTester;
21 +
22 +import static org.hamcrest.MatcherAssert.assertThat;
23 +import static org.hamcrest.Matchers.is;
24 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25 +import static org.onosproject.store.service.AtomicValueEvent.Type.UPDATE;
26 +
27 +/**
28 + * Unit tests for the AtomicValueEvent class.
29 + */
30 +public class AtomicValueEventTest {
31 +
32 + AtomicValueEvent<String> event1 =
33 + new AtomicValueEvent<>("map1", UPDATE, "e1");
34 + AtomicValueEvent<String> event2 =
35 + new AtomicValueEvent<>("map1", UPDATE, "e2");
36 + AtomicValueEvent<String> sameAsEvent2 =
37 + new AtomicValueEvent<>("map1", UPDATE, "e2");
38 + AtomicValueEvent<String> event3 =
39 + new AtomicValueEvent<>("map2", UPDATE, "e2");
40 +
41 + /**
42 + * Checks that the SetEvent class is immutable.
43 + */
44 + @Test
45 + public void testImmutability() {
46 + assertThatClassIsImmutable(AtomicValueEvent.class);
47 + }
48 +
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 + .testEquals();
59 + }
60 +
61 + /**
62 + * Checks that construction of the object is correct.
63 + */
64 + @Test
65 + public void testConstruction() {
66 + assertThat(event1.type(), is(UPDATE));
67 + assertThat(event1.value(), is("e1"));
68 + assertThat(event1.name(), is("map1"));
69 + }
70 +
71 +}
1 +/*
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 + */
16 +package org.onosproject.store.service;
17 +
18 +import org.junit.Test;
19 +
20 +import com.google.common.testing.EqualsTester;
21 +
22 +import static org.hamcrest.MatcherAssert.assertThat;
23 +import static org.hamcrest.Matchers.is;
24 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25 +import static org.onosproject.store.service.SetEvent.Type.ADD;
26 +import static org.onosproject.store.service.SetEvent.Type.REMOVE;
27 +
28 +/**
29 + * Unit tests for the SetEvent class.
30 + */
31 +public 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 +}