From 56bb558623268b4e82e6afd9a81225a8369084e4 Mon Sep 17 00:00:00 2001 From: Adam Pocock Date: Mon, 30 Nov 2020 15:08:23 -0500 Subject: [PATCH] Adding a simple unit test for EmptyResponseProcessor. --- .../response/EmptyResponseProcessor.java | 2 +- .../response/EmptyResponseProcessorTest.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Data/src/test/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessorTest.java diff --git a/Data/src/main/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessor.java b/Data/src/main/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessor.java index 90ef282a4..153e10e73 100644 --- a/Data/src/main/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessor.java +++ b/Data/src/main/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessor.java @@ -34,7 +34,7 @@ * It still requires an output factory, even though it's never used to generate * an output, because the output factory provides the type for the columnar infrastructure. */ -public class EmptyResponseProcessor> implements ResponseProcessor { +public final class EmptyResponseProcessor> implements ResponseProcessor { public static final String FIELD_NAME = "TRIBUO##NULL_RESPONSE_PROCESSOR"; diff --git a/Data/src/test/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessorTest.java b/Data/src/test/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessorTest.java new file mode 100644 index 000000000..d1deba0c2 --- /dev/null +++ b/Data/src/test/java/org/tribuo/data/columnar/processors/response/EmptyResponseProcessorTest.java @@ -0,0 +1,34 @@ +package org.tribuo.data.columnar.processors.response; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.tribuo.test.MockOutput; +import org.tribuo.test.MockOutputFactory; + +public class EmptyResponseProcessorTest { + + @Test + public void basicTest() { + MockOutputFactory outputFactory = new MockOutputFactory(); + EmptyResponseProcessor rp = new EmptyResponseProcessor<>(outputFactory); + + // Check the output factory is stored correctly + Assertions.assertEquals(outputFactory,rp.getOutputFactory()); + + // Check the field name is right + Assertions.assertEquals(EmptyResponseProcessor.FIELD_NAME, rp.getFieldName()); + + // setFieldName is a no-op on this response processor + rp.setFieldName("Something"); + Assertions.assertEquals(EmptyResponseProcessor.FIELD_NAME, rp.getFieldName()); + + // Check that it doesn't throw exceptions when given odd text, and that it always returns Optional.empty. + Assertions.assertFalse(rp.process("").isPresent()); + Assertions.assertFalse(rp.process("test").isPresent()); + Assertions.assertFalse(rp.process("!@$#$!").isPresent()); + Assertions.assertFalse(rp.process("\n").isPresent()); + Assertions.assertFalse(rp.process("\t").isPresent()); + Assertions.assertFalse(rp.process(null).isPresent()); + } + +}