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;
21 import java.io.InputStream;
22 import java.lang.reflect.Constructor;
24 public class TestUtil {
26 * Due to sonar issue you have to create a private constructor for classes
27 * that only have static methods to prevent the creation of instances. This
28 * constructor can not be coveraged / tested since it is private.
32 public static void coveragePrivateConstructorForClassesWithStaticMethodsOnly(Class<?> clazz) {
33 for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
34 if (constructor.getParameterTypes().length == 0) {
35 constructor.setAccessible(true);
37 constructor.newInstance();
38 } catch (Exception e) {
39 throw new IllegalStateException(e);
42 throw new IllegalStateException("This should only be used if the class has a singe private constructor");
47 public static byte[] loadFile(String url) {
49 InputStream stream = SystemFunctions.class.getClassLoader().getResourceAsStream(url);
50 byte[] bytes = ByteStreams.toByteArray(stream);
52 } catch (Exception e) {
53 throw new RuntimeException("Unable to load " + url, e);