]> git.basschouten.com Git - openhab-addons.git/blob
a0dde3ef0e96b06d33171f4131160042b560eeaa
[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.windcentrale.internal.dto;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.util.Arrays;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22
23 /**
24  * Tests the {@link Windmill} enum.
25  *
26  * @author Wouter Born - Initial contribution
27  */
28 @NonNullByDefault
29 public class WindmillTest {
30
31     @Test
32     public void fromName() {
33         assertThat(Windmill.fromName("Unknown Windmill"), nullValue());
34         assertThat(Windmill.fromName("De Grote Geert"), is(Windmill.DE_GROTE_GEERT));
35
36         for (Windmill windmill : Windmill.values()) {
37             assertThat(Windmill.fromName(windmill.getName()), is(windmill));
38         }
39     }
40
41     @Test
42     public void fromProjectCode() {
43         assertThat(Windmill.fromProjectCode("WND-UNKNOWN"), nullValue());
44         assertThat(Windmill.fromProjectCode("WND-GG"), is(Windmill.DE_GROTE_GEERT));
45
46         for (Windmill windmill : Windmill.values()) {
47             assertThat(Windmill.fromProjectCode(windmill.getProjectCode()), is(windmill));
48         }
49     }
50
51     @Test
52     public void namesAreUnique() {
53         int count = (int) Arrays.stream(Windmill.values()) //
54                 .map(Windmill::getName) //
55                 .distinct() //
56                 .count();
57
58         assertThat(count, is(Windmill.values().length));
59     }
60
61     @Test
62     public void projectCodesAreUnique() {
63         int count = (int) Arrays.stream(Windmill.values()) //
64                 .map(Windmill::getProjectCode) //
65                 .distinct() //
66                 .count();
67
68         assertThat(count, is(Windmill.values().length));
69     }
70 }