Ray Milkey | d083bc4 | 2015-07-22 16:34:22 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | d083bc4 | 2015-07-22 16:34:22 -0700 | [diff] [blame] | 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.EventuallyConsistentMapEvent.Type.PUT; |
| 26 | import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; |
| 27 | |
| 28 | /** |
| 29 | * Unit tests for the EventuallyConsistentMapEvent class. |
| 30 | */ |
| 31 | public 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 Milkey | 92ea9b3 | 2015-07-24 09:28:09 -0700 | [diff] [blame] | 45 | EventuallyConsistentMapEvent<String, String> event6 = |
| 46 | new EventuallyConsistentMapEvent<>("map3", REMOVE, "k1", "v2"); |
| 47 | |
Ray Milkey | d083bc4 | 2015-07-22 16:34:22 -0700 | [diff] [blame] | 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 | .addEqualityGroup(event4) |
| 59 | .addEqualityGroup(event5) |
Ray Milkey | 92ea9b3 | 2015-07-24 09:28:09 -0700 | [diff] [blame] | 60 | .addEqualityGroup(event6) |
Ray Milkey | d083bc4 | 2015-07-22 16:34:22 -0700 | [diff] [blame] | 61 | .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 | } |