samanwita pal | 74d32fd | 2015-06-25 09:22:09 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
samanwita pal | 74d32fd | 2015-06-25 09:22:09 -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 com.google.common.testing.EqualsTester; |
samanwita pal | 74d32fd | 2015-06-25 09:22:09 -0700 | [diff] [blame] | 19 | |
| 20 | import org.junit.Assert; |
| 21 | import org.junit.Test; |
| 22 | |
| 23 | import java.lang.reflect.Constructor; |
| 24 | import java.util.Arrays; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.hamcrest.Matchers.notNullValue; |
| 29 | |
| 30 | /** |
| 31 | * MultiValuedTimestamp unit tests. |
| 32 | */ |
Sho SHIMIZU | 8dc81ea | 2015-09-10 10:59:43 -0700 | [diff] [blame] | 33 | public class MultiValuedTimestampTest { |
samanwita pal | 74d32fd | 2015-06-25 09:22:09 -0700 | [diff] [blame] | 34 | |
| 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 SHIMIZU | 8dc81ea | 2015-09-10 10:59:43 -0700 | [diff] [blame] | 93 | } |