2 * Copyright (c) 2010-2021 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.junit.jupiter.api.Test;
18 import org.mockito.Mockito;
19 import org.osgi.framework.BundleContext;
22 * @author Sami Salonen - Initial contribution
24 public class SingleValueTransformationTest {
27 public void testTransformationOldStyle() {
28 SingleValueTransformation transformation = new SingleValueTransformation("REGEX(myregex:foo(.*))");
29 assertEquals("REGEX", transformation.transformationServiceName);
30 assertEquals("myregex:foo(.*)", transformation.transformationServiceParam);
34 public void testTransformationOldStyle2() {
35 SingleValueTransformation transformation = new SingleValueTransformation("REG_(EX(myregex:foo(.*))");
36 assertEquals("REG_", transformation.transformationServiceName);
37 assertEquals("EX(myregex:foo(.*)", transformation.transformationServiceParam);
41 public void testTransformationNewStyle() {
42 SingleValueTransformation transformation = new SingleValueTransformation("REGEX:myregex(.*)");
43 assertEquals("REGEX", transformation.transformationServiceName);
44 assertEquals("myregex(.*)", transformation.transformationServiceParam);
48 public void testTransformationNewStyle2() {
49 SingleValueTransformation transformation = new SingleValueTransformation("REGEX::myregex(.*)");
50 assertEquals("REGEX", transformation.transformationServiceName);
51 assertEquals(":myregex(.*)", transformation.transformationServiceParam);
55 public void testTransformationEmpty() {
56 SingleValueTransformation transformation = new SingleValueTransformation("");
57 assertFalse(transformation.isIdentityTransform());
58 assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
62 public void testTransformationNull() {
63 SingleValueTransformation transformation = new SingleValueTransformation(null);
64 assertFalse(transformation.isIdentityTransform());
65 assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
69 public void testTransformationDefault() {
70 SingleValueTransformation transformation = new SingleValueTransformation("deFault");
71 assertTrue(transformation.isIdentityTransform());
72 assertEquals("xx", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
76 public void testTransformationDefaultChainedWithStatic() {
77 SingleValueTransformation transformation = new SingleValueTransformation("static");
78 assertFalse(transformation.isIdentityTransform());
79 assertEquals("static", transformation.transform(Mockito.mock(BundleContext.class), "xx"));