Fix eclipse/checkstyle warnings
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / EvenMoreObjectsTest.java
1 /*
2  * Copyright (c) 2016 Red Hat, 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 package org.opendaylight.yangtools.util;
9
10 import static org.junit.Assert.assertTrue;
11
12 import com.google.common.base.MoreObjects;
13 import com.google.common.testing.EqualsTester;
14 import java.util.Objects;
15 import org.junit.Test;
16
17 public class EvenMoreObjectsTest {
18
19     @Test
20     public void thingPassesEqualsTester() {
21         new EqualsTester()
22                 .addEqualityGroup(new Thing("hello", 123), new Thing("hello", 123))
23                 .addEqualityGroup(new Thing("hoi", 123), new Thing("hoi", 123))
24                 .addEqualityGroup(new Thing("hoi", null))
25                 .addEqualityGroup(new Thing(null, null))
26                 .testEquals();
27     }
28
29     @Test
30     public void nullEqualsNull() {
31         assertTrue(EvenMoreObjects.equalsHelper(null, null, (one, another) -> Boolean.TRUE));
32     }
33
34     private static class Thing {
35         String name;
36         Integer age;
37
38         @Override
39         public boolean equals(final Object obj) {
40             return EvenMoreObjects.equalsHelper(this, obj,
41                 (one, another) -> Objects.equals(one.name, another.name) && Objects.equals(one.age, another.age));
42         }
43
44         @Override
45         public int hashCode() {
46             return Objects.hash(name, age);
47         }
48
49         @Override
50         public String toString() {
51             return MoreObjects.toStringHelper(this).add("name", name).add("age", age).toString();
52         }
53
54         Thing(final String name, final Integer age) {
55             super();
56             this.name = name;
57             this.age = age;
58         }
59     }
60 }