2 * Copyright 2016-2017, Nokia Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
19 import com.google.common.io.ByteStreams;
20 import java.io.InputStream;
21 import java.lang.reflect.Constructor;
23 public class TestUtil {
25 * Due to sonar issue you have to create a private constructor for classes
26 * that only have static methods to prevent the creation of instances. This
27 * constructor can not be coveraged / tested since it is private.
31 public static void coveragePrivateConstructorForClassesWithStaticMethodsOnly(Class<?> clazz) {
32 for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
33 if (constructor.getParameterTypes().length == 0) {
34 constructor.setAccessible(true);
36 constructor.newInstance();
37 } catch (Exception e) {
38 throw new IllegalStateException(e);
41 throw new IllegalStateException("This should only be used if the class has a singe private constructor");
46 public static byte[] loadFile(String url) {
48 InputStream stream = SystemFunctions.class.getClassLoader().getResourceAsStream(url);
49 byte[] bytes = ByteStreams.toByteArray(stream);
51 } catch (Exception e) {
52 throw new RuntimeException("Unable to load " + url, e);