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.mdsal.binding.spec.reflect;
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.mdsal.binding.spec.reflect.AugmentationFieldGetter.getGetter;
17 import java.util.HashMap;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.binding.Augmentation;
22 public class AugmentationFieldGetterTest {
25 public void getGetterTest() throws Exception {
26 assertTrue(getGetter(Object.class).getAugmentations(null).isEmpty());
27 assertTrue(getGetter(TestAugmentationWrongTypeClass.class).getAugmentations(null).isEmpty());
29 final AugmentationFieldGetter augmentationFieldGetter = getGetter(TestAugmentationClass.class);
30 final Augmentation<?> augmentation = mock(Augmentation.class);
31 final TestAugmentationClass testAugmentationClass = new TestAugmentationClass();
33 testAugmentationClass.addAugmentation(augmentation, augmentation);
34 assertNotNull(augmentationFieldGetter.getAugmentations(testAugmentationClass));
35 assertEquals(1, augmentationFieldGetter.getAugmentations(testAugmentationClass).size());
38 @Test(expected = IllegalStateException.class)
39 public void getWrongGetterTest() throws Exception {
40 final AugmentationFieldGetter augmentationFieldGetter = getGetter(TestAugmentationClass.class);
41 augmentationFieldGetter.getAugmentations("");
42 fail("Expected IllegalStateException");
46 public void getNoGetterTest() throws Exception {
47 assertTrue(getGetter(Object.class).getAugmentations(null).isEmpty());
50 private final class TestAugmentationClass {
51 private final Map<Augmentation<?>, Augmentation<?>> augmentation = new HashMap<>();
53 void addAugmentation(final Augmentation<?> key, final Augmentation<?> value) {
54 augmentation.put(key, value);
58 private final class TestAugmentationWrongTypeClass {
59 private String augmentation;