blob: 6c1612735d2c1a843926d639e3eb6cb96804f8a0 [file] [log] [blame]
Ray Milkey67d53cc2015-07-23 16:32:36 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey67d53cc2015-07-23 16:32:36 -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.AtomicValueEvent.Type.UPDATE;
26
27/**
28 * Unit tests for the AtomicValueEvent class.
29 */
30public class AtomicValueEventTest {
31
32 AtomicValueEvent<String> event1 =
Madan Jampani533ef982016-02-01 00:16:35 -080033 new AtomicValueEvent<>("map1", "e1", "e0");
Ray Milkey67d53cc2015-07-23 16:32:36 -070034 AtomicValueEvent<String> event2 =
Madan Jampani533ef982016-02-01 00:16:35 -080035 new AtomicValueEvent<>("map1", "e2", "e1");
Ray Milkey67d53cc2015-07-23 16:32:36 -070036 AtomicValueEvent<String> sameAsEvent2 =
Madan Jampani533ef982016-02-01 00:16:35 -080037 new AtomicValueEvent<>("map1", "e2", "e1");
Ray Milkey67d53cc2015-07-23 16:32:36 -070038 AtomicValueEvent<String> event3 =
Madan Jampani533ef982016-02-01 00:16:35 -080039 new AtomicValueEvent<>("map2", "e2", "e1");
Ray Milkey67d53cc2015-07-23 16:32:36 -070040
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 Jampani533ef982016-02-01 00:16:35 -080067 assertThat(event1.newValue(), is("e1"));
68 assertThat(event1.oldValue(), is("e0"));
Ray Milkey67d53cc2015-07-23 16:32:36 -070069 assertThat(event1.name(), is("map1"));
70 }
71
72}