1 package org.openecomp.sdc.be.utils;
3 import com.google.common.io.Resources;
5 import java.io.IOException;
7 import java.nio.charset.Charset;
8 import java.nio.charset.StandardCharsets;
11 * A set of helper method for fixture files.
13 public class FixtureHelpers {
15 private FixtureHelpers() {
20 * Reads the given fixture file from the classpath (e. g. {@code src/test/resources})
21 * and returns its contents as a UTF-8 string.
23 * @param filename the filename of the fixture file
24 * @return the contents of {@code src/test/resources/{filename}}
25 * @throws IllegalArgumentException if an I/O error occurs.
27 public static String fixture(String filename) {
28 return fixture(filename, StandardCharsets.UTF_8);
32 * Reads the given fixture file from the classpath (e. g. {@code src/test/resources})
33 * and returns its contents as a string.
35 * @param filename the filename of the fixture file
36 * @param charset the character set of {@code filename}
37 * @return the contents of {@code src/test/resources/{filename}}
38 * @throws IllegalArgumentException if an I/O error occurs.
40 private static String fixture(String filename, Charset charset) {
42 URL url = Resources.getResource(filename);
43 String text = Resources.toString(url, charset);
46 catch (IOException e) {
47 throw new IllegalArgumentException(e);