Fix checkstyle violations in yang-binding
[mdsal.git] / binding / yang-binding / src / test / java / org / opendaylight / yangtools / yang / binding / util / AugmentationFieldGetterTest.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 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Mockito.mock;
15 import static org.opendaylight.yangtools.yang.binding.util.AugmentationFieldGetter.getGetter;
16
17 import java.util.HashMap;
18 import java.util.Map;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.binding.Augmentation;
21 import org.opendaylight.yangtools.yang.binding.AugmentationHolder;
22
23 public class AugmentationFieldGetterTest {
24
25     @Test
26     public void getGetterTest() throws Exception {
27         assertNotNull(getGetter(AugmentationHolder.class));
28         assertTrue(getGetter(AugmentationHolder.class)
29                 .getAugmentations(mock(AugmentationHolder.class)).isEmpty());
30         assertTrue(getGetter(Object.class).getAugmentations(null).isEmpty());
31         assertTrue(getGetter(TestAugmentationWrongTypeClass.class).getAugmentations(null).isEmpty());
32
33         final AugmentationFieldGetter augmentationFieldGetter = getGetter(TestAugmentationClass.class);
34         final Augmentation<?> augmentation = mock(Augmentation.class);
35         final TestAugmentationClass testAugmentationClass = new TestAugmentationClass();
36
37         testAugmentationClass.addAugmentation(augmentation, augmentation);
38         assertNotNull(augmentationFieldGetter.getAugmentations(testAugmentationClass));
39         assertEquals(1, augmentationFieldGetter.getAugmentations(testAugmentationClass).size());
40     }
41
42     @Test(expected = IllegalStateException.class)
43     public void getWrongGetterTest() throws Exception {
44         final AugmentationFieldGetter augmentationFieldGetter = getGetter(TestAugmentationClass.class);
45         augmentationFieldGetter.getAugmentations(new String());
46         fail("Expected IllegalStateException");
47     }
48
49     @Test
50     public void getNoGetterTest() throws Exception {
51         assertTrue(getGetter(Object.class).getAugmentations(null).isEmpty());
52     }
53
54     private final class TestAugmentationClass {
55         private final Map<Augmentation<?>, Augmentation<?>> augmentation = new HashMap<>();
56
57         void addAugmentation(final Augmentation<?> key, final Augmentation<?> value) {
58             augmentation.put(key, value);
59         }
60     }
61
62     private final class TestAugmentationWrongTypeClass {
63         private String augmentation;
64     }
65 }