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.deutschebahn.internal.timetable;
15 import java.io.IOException;
16 import java.util.Date;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.deutschebahn.internal.timetable.dto.Timetable;
23 * Stub Implementation of {@link TimetablesV1Api}, that may return a preconfigured Timetable or
24 * throws an {@link IOException} if not data has been set.
26 * @author Sönke Küper - initial contribution
29 public final class TimetablesV1ApiStub implements TimetablesV1Api {
32 private final Timetable result;
34 private TimetablesV1ApiStub(@Nullable Timetable result) {
39 * Creates a new {@link TimetablesV1ApiStub}, that returns the given result.
41 public static TimetablesV1ApiStub createWithResult(Timetable timetable) {
42 return new TimetablesV1ApiStub(timetable);
46 * Creates a new {@link TimetablesV1ApiStub} that throws an Exception.
48 public static TimetablesV1ApiStub createWithException() {
49 return new TimetablesV1ApiStub(null);
53 public Timetable getPlan(String evaNo, Date time) throws IOException {
54 final Timetable currentResult = this.result;
55 if (currentResult == null) {
56 throw new IOException("No timetable data is available");
63 public Timetable getFullChanges(String evaNo) throws IOException {
64 return new Timetable();
68 public Timetable getRecentChanges(String evaNo) throws IOException {
69 return new Timetable();