Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -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 | 67d53cc | 2015-07-23 16:32:36 -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.AtomicValueEvent.Type.UPDATE; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for the AtomicValueEvent class. |
| 29 | */ |
| 30 | public class AtomicValueEventTest { |
| 31 | |
| 32 | AtomicValueEvent<String> event1 = |
Madan Jampani | 533ef98 | 2016-02-01 00:16:35 -0800 | [diff] [blame] | 33 | new AtomicValueEvent<>("map1", "e1", "e0"); |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 34 | AtomicValueEvent<String> event2 = |
Madan Jampani | 533ef98 | 2016-02-01 00:16:35 -0800 | [diff] [blame] | 35 | new AtomicValueEvent<>("map1", "e2", "e1"); |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 36 | AtomicValueEvent<String> sameAsEvent2 = |
Madan Jampani | 533ef98 | 2016-02-01 00:16:35 -0800 | [diff] [blame] | 37 | new AtomicValueEvent<>("map1", "e2", "e1"); |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 38 | AtomicValueEvent<String> event3 = |
Madan Jampani | 533ef98 | 2016-02-01 00:16:35 -0800 | [diff] [blame] | 39 | new AtomicValueEvent<>("map2", "e2", "e1"); |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 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)); |
Madan Jampani | 533ef98 | 2016-02-01 00:16:35 -0800 | [diff] [blame] | 67 | assertThat(event1.newValue(), is("e1")); |
| 68 | assertThat(event1.oldValue(), is("e0")); |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 69 | assertThat(event1.name(), is("map1")); |
| 70 | } |
| 71 | |
| 72 | } |