2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.testutils;
10 import static com.google.common.truth.Truth.assertThat;
12 import ch.vorburger.xtendbeans.AssertBeans;
13 import org.junit.ComparisonFailure;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
18 * Tests that the {@link AssertDataObjects} utility also works for any Java
19 * object that is not a {@link DataObject}, like the {@link AssertBeans} which
20 * it's based on. There is absolutely no particular reason why it wouldn't,
21 * because {@link AssertDataObjects} is essentially just a customization of
22 * {@link AssertBeans} - this is just to make sure none of the base
23 * functionality gets broken in the customization.
25 * @author Michael Vorburger
27 public class AssertNonDataObjectsTest {
29 public static class SomeBean {
32 public String getName() {
36 public void setName(String name) {
41 public boolean equals(Object obj) {
45 if (obj == null || getClass() != obj.getClass()) {
49 SomeBean someBean = (SomeBean) obj;
51 return name != null ? name.equals(someBean.name) : someBean.name == null;
55 public int hashCode() {
56 return name != null ? name.hashCode() : 0;
61 public void testString() {
62 AssertDataObjects.assertEqualBeans("hello, world", "hello, world");
66 public void testSomeBean() {
67 SomeBean first = new SomeBean();
68 first.setName("hello, world");
70 SomeBean second = new SomeBean();
71 second.setName("hello, world");
73 AssertDataObjects.assertEqualBeans(first, second);
77 public void testSomeBeanMismatch() {
78 SomeBean expected = new SomeBean();
79 expected.setName("hello, world 1");
81 SomeBean actual = new SomeBean();
82 actual.setName("hello, world 2");
85 AssertDataObjects.assertEqualBeans(expected, actual);
86 } catch (ComparisonFailure e) {
87 assertThat(e.getExpected()).contains("hello, world 1");
88 assertThat(e.getActual()).contains("hello, world 2");