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 org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertThrows;
15 import ch.vorburger.xtendbeans.AssertBeans;
16 import org.junit.ComparisonFailure;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
21 * Tests that the {@link AssertDataObjects} utility also works for any Java
22 * object that is not a {@link DataObject}, like the {@link AssertBeans} which
23 * it's based on. There is absolutely no particular reason why it wouldn't,
24 * because {@link AssertDataObjects} is essentially just a customization of
25 * {@link AssertBeans} - this is just to make sure none of the base
26 * functionality gets broken in the customization.
28 * @author Michael Vorburger
30 @Deprecated(since = "8.0.9", forRemoval = true)
31 public class AssertNonDataObjectsTest {
33 public static class SomeBean {
36 public String getName() {
40 public void setName(final String name) {
45 public boolean equals(final Object obj) {
49 if (obj == null || getClass() != obj.getClass()) {
53 SomeBean someBean = (SomeBean) obj;
55 return name != null ? name.equals(someBean.name) : someBean.name == null;
59 public int hashCode() {
60 return name != null ? name.hashCode() : 0;
65 public void testString() {
66 AssertDataObjects.assertEqualBeans("hello, world", "hello, world");
70 public void testSomeBean() {
71 SomeBean first = new SomeBean();
72 first.setName("hello, world");
74 SomeBean second = new SomeBean();
75 second.setName("hello, world");
77 AssertDataObjects.assertEqualBeans(first, second);
81 public void testSomeBeanMismatch() {
82 SomeBean expected = new SomeBean();
83 expected.setName("hello, world 1");
85 SomeBean actual = new SomeBean();
86 actual.setName("hello, world 2");
88 ComparisonFailure ex = assertThrows(ComparisonFailure.class,
89 () -> AssertDataObjects.assertEqualBeans(expected, actual));
90 assertThat(ex.getMessage(), startsWith("Expected and actual beans do not match"));
91 assertThat(ex.getExpected(), containsString("hello, world 1"));
92 assertThat(ex.getActual(), containsString("hello, world 2"));