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.dwdunwetter.internal.dto;
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
18 import java.time.Instant;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
24 * Tests for {@link org.openhab.binding.dwdunwetter.internal.dto.DwdWarningCache}
26 * @author Martin Koehler - Initial contribution
28 public class DwdWarningCacheTest {
30 private DwdWarningCache cache;
34 cache = new DwdWarningCache();
38 public void testAddEntry() {
39 DwdWarningData data = createData("ID", 0);
41 assertThat(cache.addEntry(data), is(true));
42 assertThat(cache.addEntry(data), is(false));
46 public void testDeleteOldEntries() {
47 DwdWarningData data = createData("ID", 0);
50 cache.deleteOldEntries();
51 assertThat(cache.addEntry(data), is(false));
53 data = createData("ID", 60 * 60);
54 assertThat(cache.addEntry(data), is(false));
55 cache.deleteOldEntries();
56 assertThat(cache.addEntry(data), is(true));
59 private DwdWarningData createData(String id, long secondsBeforeNow) {
60 DwdWarningData data = new DwdWarningData();
62 data.setExpires(Instant.now().minusSeconds(secondsBeforeNow));