Migrate common module to JUnit5
[transportpce.git] / common / src / test / java / org / opendaylight / transportpce / common / NodeIdPairTest.java
1 /*
2  * Copyright © 2018 Orange Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.common;
10
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12
13 import java.util.stream.Stream;
14 import org.junit.jupiter.params.ParameterizedTest;
15 import org.junit.jupiter.params.provider.Arguments;
16 import org.junit.jupiter.params.provider.MethodSource;
17
18 public class NodeIdPairTest {
19
20     private static Stream<Arguments> provideNodeSamples() {
21         NodeIdPair same = new NodeIdPair("nodeS", "CLIENT");
22         return Stream.of(
23             Arguments.of(new NodeIdPair("",""), null, false),
24             Arguments.of(new NodeIdPair("",""), "", false),
25             Arguments.of(new NodeIdPair("node1","PP"), new NodeIdPair("node2","PP"), false),
26             Arguments.of(new NodeIdPair("node1","PP"), new NodeIdPair("node1","TTP"), false),
27             Arguments.of(new NodeIdPair(null,"PP"), new NodeIdPair(null,"TTP"), false),
28             Arguments.of(new NodeIdPair(null,"PP"), new NodeIdPair("node2","TTP"), false),
29             Arguments.of(new NodeIdPair("node1",null), new NodeIdPair("node1","NETWORK"), false),
30             Arguments.of(new NodeIdPair("node1",null), new NodeIdPair("node1",null), true),
31             Arguments.of(new NodeIdPair("node1","TTP"), new NodeIdPair("node1","TTP"), true),
32             Arguments.of(new NodeIdPair(null,null), new NodeIdPair(null,null), true),
33             Arguments.of(same, same, true));
34     }
35
36     @ParameterizedTest
37     @MethodSource("provideNodeSamples")
38     void equalityTest(NodeIdPair firstPair, Object secondPair, boolean equality) {
39         assertEquals(equality, firstPair.equals(secondPair));
40         if ((secondPair != null) && firstPair.getClass().equals(secondPair.getClass())) {
41             assertEquals(equality, firstPair.hashCode() == secondPair.hashCode());
42         }
43     }
44 }