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.digitalstrom.internal.lib.util;
15 import static org.hamcrest.MatcherAssert.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.Matchers.contains;
18 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
20 import java.util.Arrays;
21 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputChannelEnum;
27 import com.google.gson.Gson;
28 import com.google.gson.JsonObject;
29 import com.google.gson.JsonParser;
32 * Test class for {@link DSJsonParser}
34 * @author Rouven Schürch - Initial contribution
38 class DSJsonParserTest {
41 void testParseSingleOutputchannels() {
42 JsonObject jsonObject = createJsonObject(Arrays.asList(new OutputChannel(OutputChannelEnum.BRIGHTNESS)));
44 List<OutputChannelEnum> channels = DSJsonParser.getOutputChannels(jsonObject);
45 assertThat(channels, contains(OutputChannelEnum.BRIGHTNESS));
49 void testParseMultipleOutputchannels() {
50 JsonObject jsonObject = createJsonObject(Arrays.asList(new OutputChannel(OutputChannelEnum.BRIGHTNESS),
51 new OutputChannel(OutputChannelEnum.AIR_FLAP_POSITION)));
53 List<OutputChannelEnum> channels = DSJsonParser.getOutputChannels(jsonObject);
54 assertThat(channels, contains(OutputChannelEnum.BRIGHTNESS, OutputChannelEnum.AIR_FLAP_POSITION));
58 void testParseNoOutputchannels() {
59 JsonObject jsonObject = createJsonObject(Arrays.asList());
60 List<OutputChannelEnum> channels = DSJsonParser.getOutputChannels(jsonObject);
61 assertThat(channels, hasSize(0));
64 private static JsonObject createJsonObject(List<OutputChannel> channels) {
65 JsonModel model = new JsonModel(channels);
67 Gson gson = new Gson();
68 String json = gson.toJson(model);
70 return JsonParser.parseString(json).getAsJsonObject();