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.plex.internal.handler;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
18 import java.util.concurrent.ScheduledExecutorService;
19 import java.util.stream.Stream;
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;
31 * Tests cases for {@link org.openhab.binding.plex.internal.handler.PlexApiConnector}.
33 * @author Brian Homeyer - Initial contribution
34 * @author Aron Beurskens - Added test
37 public class PlexApiConnectorTest {
38 private @NonNullByDefault({}) @Mock ScheduledExecutorService scheduler;
39 private @NonNullByDefault({}) @Mock HttpClient httpClient;
41 private @NonNullByDefault({}) PlexApiConnector plexApiConnector;
45 plexApiConnector = new PlexApiConnector(scheduler, httpClient);
49 * Test that the .hasToken check return the correct values.
51 @ParameterizedTest(name = "{index} => token={0}, result={1}")
52 @MethodSource("tokenProvider")
53 public void testHasToken(String token, Boolean result) {
54 PlexServerConfiguration config = new PlexServerConfiguration();
56 plexApiConnector.setParameters(config);
57 assertThat(plexApiConnector.hasToken(), is(result));
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));