2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.store.service;
18 import com.google.common.testing.EqualsTester;
19 import junit.framework.TestCase;
21 import org.junit.Assert;
22 import org.junit.Test;
24 import java.lang.reflect.Constructor;
25 import java.util.Arrays;
27 import static org.hamcrest.MatcherAssert.assertThat;
28 import static org.hamcrest.Matchers.is;
29 import static org.hamcrest.Matchers.notNullValue;
32 * MultiValuedTimestamp unit tests.
34 public class MultiValuedTimestampTest extends TestCase {
36 private final MultiValuedTimestamp<Integer, Integer> stats1 = new MultiValuedTimestamp<>(1, 3);
38 private final MultiValuedTimestamp<Integer, Integer> stats2 = new MultiValuedTimestamp<>(1, 2);
42 * Tests the creation of the MapEvent object.
45 public void testConstruction() {
46 assertThat(stats1.value1(), is(1));
47 assertThat(stats1.value2(), is(3));
51 * Tests the toCompare function.
54 public void testToCompare() {
55 assertThat(stats1.compareTo(stats2), is(1));
59 * Tests the equals, hashCode and toString methods using Guava EqualsTester.
62 public void testEquals() {
64 .addEqualityGroup(stats1, stats1)
65 .addEqualityGroup(stats2)
70 * Tests that the empty argument list constructor for serialization
71 * is present and creates a proper object.
74 public void testSerializerConstructor() {
76 Constructor[] constructors = MultiValuedTimestamp.class.getDeclaredConstructors();
77 assertThat(constructors, notNullValue());
78 Arrays.stream(constructors).filter(ctor ->
79 ctor.getParameterTypes().length == 0)
80 .forEach(noParamsCtor -> {
82 noParamsCtor.setAccessible(true);
83 MultiValuedTimestamp stats =
84 (MultiValuedTimestamp) noParamsCtor.newInstance();
85 assertThat(stats, notNullValue());
86 } catch (Exception e) {
87 Assert.fail("Exception instantiating no parameters constructor");
90 } catch (Exception e) {
91 Assert.fail("Exception looking up constructors");