Move StringValueObjectFactory to mdsal-binding-spec-util
[mdsal.git] / binding / mdsal-binding-spec-util / src / test / java / org / opendaylight / mdsal / binding / spec / reflect / StringValueObjectFactoryTest.java
1 /*
2  * Copyright (c) 2016 Cisco 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 package org.opendaylight.mdsal.binding.spec.reflect;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import org.junit.Test;
14
15 public class StringValueObjectFactoryTest {
16
17     @Test
18     public void createTest() throws Exception {
19         final StringValueObjectFactory<?> stringValueObjectFactory =
20                 StringValueObjectFactory.create(TestClass.class, "testTemplate");
21         assertNotNull(stringValueObjectFactory);
22         assertEquals("testTemplate", stringValueObjectFactory.getTemplate().toString());
23     }
24
25     @Test
26     public void newInstanceTest() throws Exception {
27         final StringValueObjectFactory<?> instance = StringValueObjectFactory.create(TestClass.class, "testTemplate");
28
29         assertEquals("instanceTest", instance.newInstance("instanceTest").toString());
30     }
31
32     @Test(expected = IllegalArgumentException.class)
33     public void createTestNoConstructor() throws Exception {
34         StringValueObjectFactory.create(Object.class, "");
35     }
36
37     @Test(expected = IllegalArgumentException.class)
38     public void createTestNoField() throws Exception {
39         StringValueObjectFactory.create(String.class, "");
40     }
41
42     public static final class TestClass {
43
44         @SuppressWarnings("checkstyle:memberName")
45         private final String _value;
46
47         public TestClass(final TestClass parent) {
48             this._value = parent._value;
49         }
50
51         public TestClass(final String value) {
52             this._value = value;
53         }
54
55         @Override
56         public String toString() {
57             return this._value;
58         }
59     }
60 }