Merge branch 'mdsal-trace' from controller
[mdsal.git] / binding / mdsal-binding-test-utils / src / test / java / org / opendaylight / mdsal / binding / testutils / AssertNonDataObjectsTest.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.mdsal.binding.testutils;
9
10 import static com.google.common.truth.Truth.assertThat;
11
12 import ch.vorburger.xtendbeans.AssertBeans;
13 import org.junit.ComparisonFailure;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16
17 /**
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.
24  *
25  * @author Michael Vorburger
26  */
27 public class AssertNonDataObjectsTest {
28
29     public static class SomeBean {
30         private String name;
31
32         public String getName() {
33             return name;
34         }
35
36         public void setName(String name) {
37             this.name = name;
38         }
39     }
40
41     @Test
42     public void testString() {
43         AssertDataObjects.assertEqualBeans("hello, world", "hello, world");
44     }
45
46     @Test
47     public void testSomeBean() {
48         SomeBean first = new SomeBean();
49         first.setName("hello, world");
50
51         SomeBean second = new SomeBean();
52         second.setName("hello, world");
53
54         AssertDataObjects.assertEqualBeans(first, second);
55     }
56
57     @Test
58     public void testSomeBeanMismatch() {
59         SomeBean expected = new SomeBean();
60         expected.setName("hello, world 1");
61
62         SomeBean actual = new SomeBean();
63         actual.setName("hello, world 2");
64
65         try {
66             AssertDataObjects.assertEqualBeans(expected, actual);
67         } catch (ComparisonFailure e) {
68             assertThat(e.getExpected()).contains("hello, world 1");
69             assertThat(e.getActual()).contains("hello, world 2");
70         }
71     }
72 }