3db478f9a26048ca845adecf21f9affd2d5575ee
[mdsal.git] / binding / yang-binding / src / test / java / org / opendaylight / yangtools / yang / binding / util / 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.yangtools.yang.binding.util;
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     private static final class TestClass {
43
44         private final String _value;
45
46         public TestClass(TestClass parrent) {
47             this._value = parrent._value;
48         }
49
50         public TestClass(String value) {
51             this._value = value;
52         }
53
54         @Override
55         public String toString() {
56             return this._value;
57         }
58     }
59 }