2 * Copyright (c) 2016 Cisco Systems, 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.yangtools.yang.binding.util;
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;
17 import java.util.HashMap;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.binding.Augmentation;
21 import org.opendaylight.yangtools.yang.binding.AugmentationHolder;
23 public class AugmentationFieldGetterTest {
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());
33 final AugmentationFieldGetter augmentationFieldGetter = getGetter(TestAugmentationClass.class);
34 final Augmentation<?> augmentation = mock(Augmentation.class);
35 final TestAugmentationClass testAugmentationClass = new TestAugmentationClass();
37 testAugmentationClass.addAugmentation(augmentation, augmentation);
38 assertNotNull(augmentationFieldGetter.getAugmentations(testAugmentationClass));
39 assertEquals(1, augmentationFieldGetter.getAugmentations(testAugmentationClass).size());
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");
50 public void getNoGetterTest() throws Exception {
51 assertTrue(getGetter(Object.class).getAugmentations(null).isEmpty());
54 private final class TestAugmentationClass {
55 private final Map<Augmentation<?>, Augmentation<?>> augmentation = new HashMap<>();
57 void addAugmentation(final Augmentation<?> key, final Augmentation<?> value) {
58 augmentation.put(key, value);
62 private final class TestAugmentationWrongTypeClass {
63 private String augmentation;