]> git.basschouten.com Git - openhab-addons.git/blob
f872e35f1ce4db24f4066b7f9a3e72b45183617a
[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.plex.internal.handler;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.util.concurrent.ScheduledExecutorService;
19 import java.util.stream.Stream;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jetty.client.HttpClient;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.params.ParameterizedTest;
25 import org.junit.jupiter.params.provider.Arguments;
26 import org.junit.jupiter.params.provider.MethodSource;
27 import org.mockito.Mock;
28 import org.openhab.binding.plex.internal.config.PlexServerConfiguration;
29
30 /**
31  * Tests cases for {@link org.openhab.binding.plex.internal.handler.PlexApiConnector}.
32  *
33  * @author Brian Homeyer - Initial contribution
34  * @author Aron Beurskens - Added test
35  */
36 @NonNullByDefault
37 public class PlexApiConnectorTest {
38     private @NonNullByDefault({}) @Mock ScheduledExecutorService scheduler;
39     private @NonNullByDefault({}) @Mock HttpClient httpClient;
40
41     private @NonNullByDefault({}) PlexApiConnector plexApiConnector;
42
43     @BeforeEach
44     public void setUp() {
45         plexApiConnector = new PlexApiConnector(scheduler, httpClient);
46     }
47
48     /**
49      * Test that the .hasToken check return the correct values.
50      */
51     @ParameterizedTest(name = "{index} => token={0}, result={1}")
52     @MethodSource("tokenProvider")
53     public void testHasToken(String token, Boolean result) {
54         PlexServerConfiguration config = new PlexServerConfiguration();
55         config.token = token;
56         plexApiConnector.setParameters(config);
57         assertThat(plexApiConnector.hasToken(), is(result));
58     }
59
60     private static Stream<Arguments> tokenProvider() {
61         return Stream.of(Arguments.of("123", true), Arguments.of("   ", false),
62                 Arguments.of("fdsjkghdf-dsjfhs-dsafkshj", true), Arguments.of("", false));
63     }
64 }