2 * Copyright (c) 2010-2020 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.networkupstools.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.Optional;
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
21 import org.apache.commons.lang.StringUtils;
22 import org.junit.jupiter.api.Test;
25 * Test class to check the validity of the {@link NutName} enum.
27 * @author Hilbrand Bouwkamp - Initial contribution
29 public class NutNameTest {
31 private static final Pattern CHANNEL_PATTERN = Pattern.compile("(\\w+)\\.(\\w+)\\.?(\\w+)?\\.?(\\w+)?");
34 * Tests if the name in {@link NutName} enum matches with the channelID in the enum.
37 public void testChannelIdName() {
38 for (final NutName nn : NutName.values()) {
39 final Matcher matcher = CHANNEL_PATTERN.matcher(nn.getName());
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");