]> git.basschouten.com Git - openhab-addons.git/blob
d3b541a9e500b2eba85c2fb80609ad30bed87eb2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sleepiq.api.test;
14
15 import java.io.File;
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;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25
26 /**
27  * The {@link AbstractTest} tests deserialization of a sleepiq API objects.
28  *
29  * @author Gregory Moyer - Initial contribution
30  */
31 @NonNullByDefault
32 public abstract class AbstractTest {
33     private static final String RESOURCES_PATH = "src/test/resources/";
34
35     protected File getTestDataFile(String name) {
36         return getTestDataPath(name).toFile();
37     }
38
39     @SuppressWarnings("null")
40     protected Path getTestDataPath(String name) {
41         String packageName = this.getClass().getPackage().getName();
42
43         List<String> paths = new ArrayList<>();
44         paths.addAll(Arrays.asList(packageName.split("\\.")));
45         paths.add(name);
46
47         return Paths.get(RESOURCES_PATH, paths.toArray(new String[paths.size()]));
48     }
49
50     protected String readJson(String jsonFileName) throws IOException {
51         return String.join("\n", Files.readAllLines(getTestDataPath(jsonFileName)));
52     }
53 }