2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sleepiq.api.test;
16 import java.io.IOException;
17 import java.nio.file.Files;
18 import java.nio.file.Path;
19 import java.nio.file.Paths;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
27 * The {@link AbstractTest} tests deserialization of a sleepiq API objects.
29 * @author Gregory Moyer - Initial contribution
32 public abstract class AbstractTest {
33 private static final String RESOURCES_PATH = "src/test/resources/";
35 protected File getTestDataFile(String name) {
36 return getTestDataPath(name).toFile();
39 @SuppressWarnings("null")
40 protected Path getTestDataPath(String name) {
41 String packageName = this.getClass().getPackage().getName();
43 List<String> paths = new ArrayList<>();
44 paths.addAll(Arrays.asList(packageName.split("\\.")));
47 return Paths.get(RESOURCES_PATH, paths.toArray(new String[paths.size()]));
50 protected String readJson(String jsonFileName) throws IOException {
51 return String.join("\n", Files.readAllLines(getTestDataPath(jsonFileName)));