b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.utils; |
| 18 | |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 19 | import java.lang.reflect.Constructor; |
| 20 | import java.lang.reflect.InvocationTargetException; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 21 | |
| 22 | import org.junit.Rule; |
| 23 | import org.junit.Test; |
| 24 | import org.junit.rules.ExpectedException; |
| 25 | |
| 26 | import static org.hamcrest.core.IsNot.not; |
| 27 | import static org.junit.Assert.assertThat; |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Test case for testing the util constants. |
| 31 | */ |
| 32 | public final class UtilConstantsTest { |
| 33 | |
| 34 | @Rule |
| 35 | public ExpectedException thrown = ExpectedException.none(); |
| 36 | |
| 37 | /** |
| 38 | * A private constructor is tested. |
| 39 | * |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 40 | * @throws SecurityException if any security violation is observed |
| 41 | * @throws NoSuchMethodException if when the method is not found |
| 42 | * @throws IllegalArgumentException if there is illegal argument found |
| 43 | * @throws InstantiationException if instantiation is provoked for the private constructor |
| 44 | * @throws IllegalAccessException if instance is provoked or a method is provoked |
| 45 | * @throws InvocationTargetException when an exception occurs by the method or constructor |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 46 | */ |
| 47 | @Test |
| 48 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 49 | InstantiationException, IllegalAccessException, InvocationTargetException { |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 50 | |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 51 | Class<?>[] classesToConstruct = {UtilConstants.class }; |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 52 | for (Class<?> clazz : classesToConstruct) { |
| 53 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 54 | constructor.setAccessible(true); |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 55 | assertThat(null, not(constructor.newInstance())); |
b.janani | 68c55e1 | 2016-02-24 12:23:03 +0530 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | } |