You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/07/22 14:35:06 UTC

[tomcat] branch 9.0.x updated: Add a test for enumerating headers names when one is null

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

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 00f53e4  Add a test for enumerating headers names when one is null
00f53e4 is described below

commit 00f53e455b90454b8e45efadcfde02bafd507de3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jul 22 15:31:11 2021 +0100

    Add a test for enumerating headers names when one is null
---
 .../apache/tomcat/util/http/TestMimeHeaders.java   | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/test/org/apache/tomcat/util/http/TestMimeHeaders.java b/test/org/apache/tomcat/util/http/TestMimeHeaders.java
index b040ed8..efc7832 100644
--- a/test/org/apache/tomcat/util/http/TestMimeHeaders.java
+++ b/test/org/apache/tomcat/util/http/TestMimeHeaders.java
@@ -16,6 +16,10 @@
  */
 package org.apache.tomcat.util.http;
 
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -24,6 +28,9 @@ public class TestMimeHeaders {
     public static final String HEADER_NAME_LC_STRING = "test";
     public static final String HEADER_NAME_UC_STRING = "TEST";
     public static final String HEADER_NAME_MIXED_STRING = "tEsT";
+    public static final String HEADER_NAME_A = "aaa";
+    public static final String HEADER_NAME_B = "bbb";
+    public static final String HEADER_NAME_C = "ccc";
 
     @Test
     public void testSetValueStringIgnoresCase01() {
@@ -61,4 +68,43 @@ public class TestMimeHeaders {
         Assert.assertEquals(HEADER_NAME_MIXED_STRING, mh.getValue(HEADER_NAME_MIXED_STRING).toString());
     }
 
+    @Test
+    public void testNamesEnumerator() {
+        MimeHeaders mh = new MimeHeaders();
+
+        mh.setValue(HEADER_NAME_A);
+        mh.setValue(HEADER_NAME_B);
+        mh.setValue(HEADER_NAME_C);
+
+        Set<String> expected = new HashSet<>();
+        expected.add(HEADER_NAME_A);
+        expected.add(HEADER_NAME_B);
+        expected.add(HEADER_NAME_C);
+
+        Enumeration<String> names = mh.names();
+        while (names.hasMoreElements()) {
+            Assert.assertTrue(expected.remove(names.nextElement()));
+        }
+        Assert.assertFalse(names.hasMoreElements());
+    }
+
+    @Test
+    public void testNamesEnumeratorWithNull() {
+        MimeHeaders mh = new MimeHeaders();
+
+        mh.setValue(HEADER_NAME_A);
+        mh.setValue(null);
+        mh.setValue(HEADER_NAME_C);
+
+        Set<String> expected = new HashSet<>();
+        expected.add(HEADER_NAME_A);
+        expected.add(null);
+        expected.add(HEADER_NAME_C);
+
+        Enumeration<String> names = mh.names();
+        while (names.hasMoreElements()) {
+            Assert.assertTrue(expected.remove(names.nextElement()));
+        }
+        Assert.assertFalse(names.hasMoreElements());
+    }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org