You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2024/02/23 07:11:11 UTC

(streampipes) branch dev updated: test: add tests for commons parser (#2487)

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new d4c4c6be61 test: add tests for commons parser (#2487)
d4c4c6be61 is described below

commit d4c4c6be61c25bf78187cb881a5cf5078132ad4b
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Fri Feb 23 08:10:59 2024 +0100

    test: add tests for commons parser (#2487)
---
 .../commons/parser/BooleanParserTest.java          | 53 ++++++++++++++++++++++
 .../commons/parser/FloatParserTest.java            | 44 ++++++++++++++++++
 .../commons/parser/IntegerParserTest.java          | 44 ++++++++++++++++++
 .../commons/parser/StringParserTest.java           | 34 ++++++++++++++
 4 files changed, 175 insertions(+)

diff --git a/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/BooleanParserTest.java b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/BooleanParserTest.java
new file mode 100644
index 0000000000..e0f142bdf1
--- /dev/null
+++ b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/BooleanParserTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.parser;
+
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class BooleanParserTest {
+
+  private BooleanParser parser;
+
+  @Before
+  public void setup() {
+    parser = new BooleanParser();
+  }
+
+  @Test
+  public void parseTrue() {
+    assertTrue(parser.parse("true"));
+  }
+
+  @Test
+  public void parseFalse() {
+    assertFalse(parser.parse("false"));
+  }
+
+  @Test
+  public void parseNotABoolean() {
+    assertFalse(parser.parse("not a boolean"));
+  }
+
+
+}
\ No newline at end of file
diff --git a/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/FloatParserTest.java b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/FloatParserTest.java
new file mode 100644
index 0000000000..1fce65e5aa
--- /dev/null
+++ b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/FloatParserTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.parser;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+public class FloatParserTest {
+  private FloatParser parser;
+
+  @Before
+  public void setup() {
+    parser = new FloatParser();
+  }
+
+  @Test
+  public void parseValidFloat() {
+    assertEquals(123.45f, parser.parse("123.45"), 0.0001);
+  }
+
+  @Test
+  public void parseInvalidFloat() {
+    assertThrows(NumberFormatException.class, () -> parser.parse("stringValue"));
+  }
+}
diff --git a/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/IntegerParserTest.java b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/IntegerParserTest.java
new file mode 100644
index 0000000000..c127f2fbc2
--- /dev/null
+++ b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/IntegerParserTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.parser;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+public class IntegerParserTest {
+  private IntegerParser parser;
+
+  @Before
+  public void setup() {
+    parser = new IntegerParser();
+  }
+
+  @Test
+  public void parseValidInteger() {
+    assertEquals(1, (int) parser.parse("1"));
+  }
+
+  @Test
+  public void parseInvalidInteger() {
+    assertThrows(NumberFormatException.class, () -> parser.parse("stringValue"));
+  }
+}
diff --git a/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/StringParserTest.java b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/StringParserTest.java
new file mode 100644
index 0000000000..bfcc171c29
--- /dev/null
+++ b/streampipes-commons/src/test/java/org/apache/streampipes/commons/parser/StringParserTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.commons.parser;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class StringParserTest {
+
+  @Test
+  public void testParse() {
+    StringParser stringParser = new StringParser();
+
+    String input = "test string";
+    assertEquals(input, stringParser.parse(input));
+  }
+}