You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by ha...@apache.org on 2026/09/07 18:42:51 UTC

(knox) branch master updated: KNOX-3439: Add tests for NoClassNameMultiLineToStringStyle (#1378)

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

hanicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b90d0da3 KNOX-3439: Add tests for NoClassNameMultiLineToStringStyle (#1378)
7b90d0da3 is described below

commit 7b90d0da3ae3a9c2e10a9a93900f1728930d3b2f
Author: Raghav Maheshwari <16...@users.noreply.github.com>
AuthorDate: Tue Sep 8 00:12:45 2026 +0530

    KNOX-3439: Add tests for NoClassNameMultiLineToStringStyle (#1378)
    
    Co-authored-by: Raghav Maheshwari <ra...@komprise.com>
---
 .../NoClassNameMultiLineToStringStyleTest.java     | 71 ++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/NoClassNameMultiLineToStringStyleTest.java b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/NoClassNameMultiLineToStringStyleTest.java
new file mode 100644
index 000000000..47fc2093f
--- /dev/null
+++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/NoClassNameMultiLineToStringStyleTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.knox.gateway.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.junit.Test;
+
+public class NoClassNameMultiLineToStringStyleTest {
+
+  @Test
+  public void shouldFormatFieldsOnSeparateLines() {
+    final Object object = new Object();
+
+    final String result = new ToStringBuilder(object, new NoClassNameMultiLineToStringStyle())
+        .append("name", "knox")
+        .append("port", 8443)
+        .toString();
+
+    final String expected = "name=knox" + System.lineSeparator()
+        + "port=8443" + System.lineSeparator();
+
+    assertEquals(expected, result);
+  }
+
+  @Test
+  public void shouldNotIncludeClassNameOrIdentityHashCode() {
+    final Object object = new Object();
+
+    final String result = new ToStringBuilder(object, new NoClassNameMultiLineToStringStyle())
+        .append("name", "knox")
+        .toString();
+
+    assertFalse(result.contains(object.getClass().getName()));
+    assertFalse(result.contains(Integer.toHexString(System.identityHashCode(object))));
+  }
+
+  @Test
+  public void shouldNotAddSeparatorBeforeFirstField() {
+    final String result = new ToStringBuilder(new Object(), new NoClassNameMultiLineToStringStyle())
+        .append("name", "knox")
+        .toString();
+
+    assertEquals("name=knox" + System.lineSeparator(), result);
+  }
+
+  @Test
+  public void shouldEndWithLineSeparatorWhenNoFieldsAreAdded() {
+    final String result =
+        new ToStringBuilder(new Object(), new NoClassNameMultiLineToStringStyle()).toString();
+
+    assertEquals(System.lineSeparator(), result);
+  }
+}