blob: 53eebe893fbf892a5d262840bbc86094e5dbcabe [file] [log] [blame]
samanwita pal74d32fd2015-06-25 09:22:09 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
samanwita pal74d32fd2015-06-25 09:22:09 -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 com.google.common.testing.EqualsTester;
samanwita pal74d32fd2015-06-25 09:22:09 -070019
20import org.junit.Assert;
21import org.junit.Test;
22
23import java.lang.reflect.Constructor;
24import java.util.Arrays;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28import static org.hamcrest.Matchers.notNullValue;
29
30/**
31 * MultiValuedTimestamp unit tests.
32 */
Sho SHIMIZU8dc81ea2015-09-10 10:59:43 -070033public class MultiValuedTimestampTest {
samanwita pal74d32fd2015-06-25 09:22:09 -070034
35 private final MultiValuedTimestamp<Integer, Integer> stats1 = new MultiValuedTimestamp<>(1, 3);
36
37 private final MultiValuedTimestamp<Integer, Integer> stats2 = new MultiValuedTimestamp<>(1, 2);
38
39
40 /**
41 * Tests the creation of the MapEvent object.
42 */
43 @Test
44 public void testConstruction() {
45 assertThat(stats1.value1(), is(1));
46 assertThat(stats1.value2(), is(3));
47 }
48
49 /**
50 * Tests the toCompare function.
51 */
52 @Test
53 public void testToCompare() {
54 assertThat(stats1.compareTo(stats2), is(1));
55 }
56
57 /**
58 * Tests the equals, hashCode and toString methods using Guava EqualsTester.
59 */
60 @Test
61 public void testEquals() {
62 new EqualsTester()
63 .addEqualityGroup(stats1, stats1)
64 .addEqualityGroup(stats2)
65 .testEquals();
66 }
67
68 /**
69 * Tests that the empty argument list constructor for serialization
70 * is present and creates a proper object.
71 */
72 @Test
73 public void testSerializerConstructor() {
74 try {
75 Constructor[] constructors = MultiValuedTimestamp.class.getDeclaredConstructors();
76 assertThat(constructors, notNullValue());
77 Arrays.stream(constructors).filter(ctor ->
78 ctor.getParameterTypes().length == 0)
79 .forEach(noParamsCtor -> {
80 try {
81 noParamsCtor.setAccessible(true);
82 MultiValuedTimestamp stats =
83 (MultiValuedTimestamp) noParamsCtor.newInstance();
84 assertThat(stats, notNullValue());
85 } catch (Exception e) {
86 Assert.fail("Exception instantiating no parameters constructor");
87 }
88 });
89 } catch (Exception e) {
90 Assert.fail("Exception looking up constructors");
91 }
92 }
Sho SHIMIZU8dc81ea2015-09-10 10:59:43 -070093}