4ef25ae02e2e30227684efc42dc8a5b7c366111e
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / sal / binding / test / AugmentationVerifier.java
1 /*
2  * Copyright (c) 2014 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.controller.sal.binding.test;
9
10 import static org.junit.Assert.assertNotNull;
11 import org.opendaylight.yangtools.yang.binding.Augmentable;
12 import org.opendaylight.yangtools.yang.binding.Augmentation;
13
14 public class AugmentationVerifier<T extends Augmentable<T>> {
15
16     private T object;
17
18     public AugmentationVerifier(T objectToVerify) {
19         this.object = objectToVerify;
20     }
21
22     public AugmentationVerifier<T> assertHasAugmentation(Class<? extends Augmentation<T>> augmentation) {
23         assertHasAugmentation(object, augmentation);
24         return this;
25     }
26
27     public static <T extends Augmentable<T>> void assertHasAugmentation(T object,
28             Class<? extends Augmentation<T>> augmentation) {
29         assertNotNull(object);
30         assertNotNull("Augmentation " + augmentation.getSimpleName() + " is not present.", object.getAugmentation(augmentation));
31     }
32
33     public static <T extends Augmentable<T>> AugmentationVerifier<T> from(T obj) {
34         return new AugmentationVerifier<T>(obj);
35     }
36
37 }