]> git.basschouten.com Git - openhab-addons.git/blob
cd6b05e0e58a796fb63afc8f216857020e24f1bc
[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.mielecloud.internal.webservice.exception;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19
20 /**
21  * @author Björn Lange - Initial contribution
22  */
23 @NonNullByDefault
24 public class TooManyRequestsExceptionTest {
25     @Test
26     public void testHasRetryAfterHintReturnsFalseWhenNoRetryAfterWasPassedToConstructor() {
27         // given:
28         TooManyRequestsException exception = new TooManyRequestsException("", null);
29
30         // when:
31         boolean result = exception.hasRetryAfterHint();
32
33         // then:
34         assertFalse(result);
35     }
36
37     @Test
38     public void testHasRetryAfterHintReturnsTrueWhenRetryAfterWasPassedToConstructor() {
39         // given:
40         TooManyRequestsException exception = new TooManyRequestsException("", "25");
41
42         // when:
43         boolean result = exception.hasRetryAfterHint();
44
45         // then:
46         assertTrue(result);
47     }
48
49     @Test
50     public void testGetSecondsUntilRetryReturnsMinusOneWhenNoRetryAfterHintIsPresent() {
51         // given:
52         TooManyRequestsException exception = new TooManyRequestsException("", null);
53
54         // when:
55         long result = exception.getSecondsUntilRetry();
56
57         // then:
58         assertEquals(-1L, result);
59     }
60
61     @Test
62     public void testGetSecondsUntilRetryParsesNumber() {
63         // given:
64         TooManyRequestsException exception = new TooManyRequestsException("", "30");
65
66         // when:
67         long result = exception.getSecondsUntilRetry();
68
69         // then:
70         assertEquals(30L, result);
71     }
72
73     @Test
74     public void testGetSecondsUntilRetryParsesDate() {
75         // given:
76         TooManyRequestsException exception = new TooManyRequestsException("", "Thu, 12 Jan 5015 15:02:30 GMT");
77
78         // when:
79         long result = exception.getSecondsUntilRetry();
80
81         // then:
82         assertNotEquals(0L, result);
83     }
84
85     @Test
86     public void testGetSecondsUntilRetryParsesDateFromThePast() {
87         // given:
88         TooManyRequestsException exception = new TooManyRequestsException("", "Wed, 21 Oct 2015 07:28:00 GMT");
89
90         // when:
91         long result = exception.getSecondsUntilRetry();
92
93         // then:
94         assertEquals(0L, result);
95     }
96
97     @Test
98     public void testGetSecondsUntilRetryReturnsMinusOneWhenDateCannotBeParsed() {
99         // given:
100         TooManyRequestsException exception = new TooManyRequestsException("", "50 Minutes");
101
102         // when:
103         long result = exception.getSecondsUntilRetry();
104
105         // then:
106         assertEquals(-1L, result);
107     }
108 }