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.filter;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.regex.Pattern;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.deutschebahn.internal.EventAttribute;
22 import org.openhab.binding.deutschebahn.internal.EventAttributeSelection;
23 import org.openhab.binding.deutschebahn.internal.EventType;
24 import org.openhab.binding.deutschebahn.internal.TripLabelAttribute;
25 import org.openhab.binding.deutschebahn.internal.timetable.dto.Event;
26 import org.openhab.binding.deutschebahn.internal.timetable.dto.TimetableStop;
27 import org.openhab.binding.deutschebahn.internal.timetable.dto.TripLabel;
30 * Tests for {@link TimetableStopByStringEventAttributeFilter}
32 * @author Sönke Küper - Initial contribution.
35 public final class TimetableByStringEventAttributeFilterTest {
38 public void testFilterTripLabelAttribute() {
39 final TimetableStopByStringEventAttributeFilter filter = new TimetableStopByStringEventAttributeFilter(
40 TripLabelAttribute.C, Pattern.compile("IC.*"));
41 final TimetableStop stop = new TimetableStop();
43 // TripLabel is not set -> does not match
44 assertFalse(filter.test(stop));
46 final TripLabel label = new TripLabel();
49 // Attribute is not set -> does not match
50 assertFalse(filter.test(stop));
52 // Set attribute -> matches depending on value
54 assertFalse(filter.test(stop));
56 assertTrue(filter.test(stop));
58 assertTrue(filter.test(stop));
62 public void testFilterEventAttribute() {
63 final EventAttributeSelection eventAttribute = new EventAttributeSelection(EventType.DEPARTURE,
65 final TimetableStopByStringEventAttributeFilter filter = new TimetableStopByStringEventAttributeFilter(
66 eventAttribute, Pattern.compile("RE.*"));
67 final TimetableStop stop = new TimetableStop();
69 // Event is not set -> does not match
70 assertFalse(filter.test(stop));
72 Event event = new Event();
75 // Attribute is not set -> does not match
76 assertFalse(filter.test(stop));
78 // Set attribute -> matches depending on value
80 assertFalse(filter.test(stop));
82 assertFalse(filter.test(stop));
84 assertTrue(filter.test(stop));
89 assertFalse(filter.test(stop));
93 public void testFilterEventAttributeList() {
94 final EventAttributeSelection eventAttribute = new EventAttributeSelection(EventType.DEPARTURE,
96 final TimetableStopByStringEventAttributeFilter filter = new TimetableStopByStringEventAttributeFilter(
97 eventAttribute, Pattern.compile("Hannover.*"));
98 final TimetableStop stop = new TimetableStop();
99 Event event = new Event();
102 event.setPpth("Hannover Hbf|Hannover-Kleefeld|Hannover Karl-Wiechert-Allee|Hannover Anderten-Misburg|Ahlten");
103 assertTrue(filter.test(stop));
105 "Ahlten|Hannover Hbf|Hannover-Kleefeld|Hannover Karl-Wiechert-Allee|Hannover Anderten-Misburg|Ahlten");
106 assertTrue(filter.test(stop));
108 "Wolfsburg Hbf|Fallersleben|Calberlah|Gifhorn|Leiferde(b Gifhorn)|Meinersen|Dedenhausen|Dollbergen|Immensen-Arpke");
109 assertFalse(filter.test(stop));