2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.javav2.runtime.reflection;
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.javav2.runtime.reflection.AugmentationFieldGetter.getGetter;
17 import java.util.HashMap;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
21 import org.opendaylight.mdsal.binding.javav2.spec.structural.AugmentationHolder;
23 public class AugmentationFieldGetterTest {
25 @SuppressWarnings("rawtypes")
27 public void getGetterTest() throws Exception {
28 assertNotNull(getGetter(AugmentationHolder.class));
29 assertTrue(getGetter(AugmentationHolder.class).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("");
46 fail("Expected IllegalStateException");
50 public void getNoGetterTest() throws Exception {
51 assertTrue(getGetter(Object.class).getAugmentations(null).isEmpty());
54 private final class TestAugmentationClass {
55 @SuppressWarnings("rawtypes")
56 private final Map augmentation = new HashMap();
58 @SuppressWarnings({ "rawtypes", "unchecked" })
59 void addAugmentation(final Augmentation key, final Augmentation value) {
60 this.augmentation.put(key, value);
64 private final class TestAugmentationWrongTypeClass {
65 @SuppressWarnings("unused")
66 private String augmentation;