]> git.basschouten.com Git - openhab-addons.git/blob
d319e36bb54455013e457e03f749a3a98e7b4282
[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.api.json;
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 ErrorMessageTest {
25
26     @Test
27     public void testErrorMessageCanBeCreated() {
28         // given:
29         String json = "{\"message\": \"Unauthorized\"}";
30
31         // when:
32         ErrorMessage errorMessage = ErrorMessage.fromJson(json);
33
34         // then:
35         assertEquals("Unauthorized", errorMessage.getMessage().get());
36     }
37
38     @Test
39     public void testErrorMessageCreationThrowsMieleSyntaxExceptionWhenJsonIsInvalid() {
40         // given:
41         String json = "\"message\": \"Unauthorized}";
42
43         // when:
44         assertThrows(MieleSyntaxException.class, () -> {
45             ErrorMessage.fromJson(json);
46         });
47     }
48 }