]> git.basschouten.com Git - openhab-addons.git/blob
b683da29eca8b359a4f1ced1e1a225ce2e32c7a8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.networkupstools.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Optional;
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.junit.jupiter.api.Test;
23
24 /**
25  * Test class to check the validity of the {@link NutName} enum.
26  *
27  * @author Hilbrand Bouwkamp - Initial contribution
28  */
29 public class NutNameTest {
30
31     private static final Pattern CHANNEL_PATTERN = Pattern.compile("(\\w+)\\.(\\w+)\\.?(\\w+)?\\.?(\\w+)?");
32
33     /**
34      * Tests if the name in {@link NutName} enum matches with the channelID in the enum.
35      */
36     @Test
37     public void testChannelIdName() {
38         for (final NutName nn : NutName.values()) {
39             final Matcher matcher = CHANNEL_PATTERN.matcher(nn.getName());
40
41             assertTrue(matcher.find(), "NutName name '" + nn + "' could not be matched with expected pattern.");
42             final String expectedChannelId = matcher.group(1)
43                     + StringUtils.capitalize(Optional.ofNullable(matcher.group(2)).orElse(""))
44                     + StringUtils.capitalize(Optional.ofNullable(matcher.group(3)).orElse(""))
45                     + StringUtils.capitalize(Optional.ofNullable(matcher.group(4)).orElse(""));
46             assertEquals(expectedChannelId, nn.getChannelId(), "Channel name not correct");
47         }
48     }
49 }