ppkarwasz commented on code in PR #3510:
URL: https://github.com/apache/logging-log4j2/pull/3510#discussion_r1980124736


##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/StringMatchFilterTest.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.logging.log4j.core.filter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@link StringMatchFilter}.
+ */
+class StringMatchFilterTest {
+
+    /**
+     * Test the normal valid programmatic instantiation of a {@link 
StringMatchFilter} via its builder.
+     */
+    @Test
+    void testFilterBuilderOK() {
+        StringMatchFilter.Builder stringMatchFilterBuilder = 
StringMatchFilter.newBuilder();
+        stringMatchFilterBuilder.setText("foo");
+        StringMatchFilter stringMatchFilter = stringMatchFilterBuilder.build();
+        assertNotNull(stringMatchFilter, "The filter should not be null.");
+        assertEquals("foo", stringMatchFilter.getText());
+    }
+
+    /**
+     * Test that if no match-string is set on the builder, the '{@link 
StringMatchFilter.Builder#build()}' returns
+     * {@code null}.
+     */
+    @Test
+    void testFilterBuilderFailsWithNullText() {
+        StringMatchFilter.Builder stringMatchFilterBuilder = 
StringMatchFilter.newBuilder();
+        Assertions.assertNull(stringMatchFilterBuilder.build());
+    }
+
+    /**
+     * Test that if a {@code null} string is set as a match-pattern, an {@code 
IllegalArgumentExeption} is thrown.
+     */
+    @Test
+    @SuppressWarnings({"DataFlowIssue" // invalid null parameter explicitly 
being tested
+    })
+    void testFilterBuilderFailsWithExceptionOnNullText() {
+        StringMatchFilter.Builder stringMatchFilterBuilder = 
StringMatchFilter.newBuilder();
+        Assertions.assertThrows(IllegalArgumentException.class, () -> 
stringMatchFilterBuilder.setText(null));

Review Comment:
   Maybe we can modify `Assert.requireNonEmpty`? What do you think?
   
   It is mostly a question of convention (and we have none), but I think that 
it is worth differentiating the `null` and empty cases, since there are plenty 
of tools that do static analysis on `null`s and the caller could use one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to