2 * Copyright (c) 2010-2024 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.modbus.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.mockito.Mockito;
20 import org.osgi.framework.BundleContext;
23 * @author Sami Salonen - Initial contribution
26 public class SingleValueTransformationTest {
29 public void testTransformationOldStyle() {
30 SingleValueTransformation transformation = new SingleValueTransformation("REGEX(myregex:foo(.*))");
31 assertEquals("REGEX", transformation.transformationServiceName);
32 assertEquals("myregex:foo(.*)", transformation.transformationServiceParam);
36 public void testTransformationOldStyle2() {
37 SingleValueTransformation transformation = new SingleValueTransformation("REG_(EX(myregex:foo(.*))");
38 assertEquals("REG_", transformation.transformationServiceName);
39 assertEquals("EX(myregex:foo(.*)", transformation.transformationServiceParam);
43 public void testTransformationNewStyle() {
44 SingleValueTransformation transformation = new SingleValueTransformation("REGEX:myregex(.*)");
45 assertEquals("REGEX", transformation.transformationServiceName);
46 assertEquals("myregex(.*)", transformation.transformationServiceParam);
50 public void testTransformationNewStyle2() {
51 SingleValueTransformation transformation = new SingleValueTransformation("REGEX::myregex(.*)");
52 assertEquals("REGEX", transformation.transformationServiceName);
53 assertEquals(":myregex(.*)", transformation.transformationServiceParam);
57 public void testTransformationEmpty() {
58 SingleValueTransformation transformation = new SingleValueTransformation("");
59 assertFalse(transformation.isIdentityTransform());
60 assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
64 public void testTransformationNull() {
65 SingleValueTransformation transformation = new SingleValueTransformation(null);
66 assertFalse(transformation.isIdentityTransform());
67 assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
71 public void testTransformationDefault() {
72 SingleValueTransformation transformation = new SingleValueTransformation("deFault");
73 assertTrue(transformation.isIdentityTransform());
74 assertEquals("xx", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
78 public void testTransformationDefaultChainedWithStatic() {
79 SingleValueTransformation transformation = new SingleValueTransformation("static");
80 assertFalse(transformation.isIdentityTransform());
81 assertEquals("static", transformation.transform(Mockito.mock(BundleContext.class), "xx"));