FSchumacher commented on code in PR #5812: URL: https://github.com/apache/jmeter/pull/5812#discussion_r1174550211
########## src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPQueryMapTest.java: ########## @@ -0,0 +1,45 @@ +/* + * 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.jmeter.protocol.http.visualizers; + +import java.util.Map; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class RequestViewHTTPQueryMapTest { + + private static Stream<Arguments> data() { + return Stream.of( + Arguments.of("k1=v1&=&k2=v2", 2), + Arguments.of("=", 0), + Arguments.of("k1=v1&=value&k2=v2", 3)); + } + + @ParameterizedTest + @MethodSource("data") + public void testGetQueryMapWithEmptyKeyAndValue(String query, int numParamExpect) { + Map<String, String[]> params = RequestViewHTTP.getQueryMap(query); + Assertions.assertNotNull(params); + Assertions.assertEquals(numParamExpect, params.size()); Review Comment: I haven't found a pre-built way to simulate the Java 11 API for creating Maps of entries, so I tried the following code to simulate it: ```java @SafeVarargs private static Map<String, List<String>> mapOf(Pair<String, String>... args) { Map<String, List<String>> results = new HashMap<>(); Arrays.stream(args) .forEach(arg -> results.put(arg.getKey(), Arrays.asList(arg.getValue().split(","))) ); return results; } private static Stream<Arguments> data() { return Stream.of(Arguments.of("k1=v1&=&k2=v2", mapOf( Pair.of("k1", "v1"), Pair.of("k2", "v2") )), Arguments.of("=", mapOf()), Arguments.of("k1=v1&=value&k2=v2", mapOf( Pair.of("k1", "v1"), Pair.of("", "value"), Pair.of("k2", "v2") )), Arguments.of("a=1&a=2&=abc&=def", mapOf( Pair.of("a", "1,2"), Pair.of("", "abc,def") )) ); } @ParameterizedTest @MethodSource("data") public void testGetQueryMapWithEmptyKeyAndValue(String query, Map<String, List<String>> expected) { Map<String, String[]> params = RequestViewHTTP.getQueryMap(query); Assertions.assertNotNull(params); Assertions.assertEquals(expected.size(), params.size()); expected.forEach((key, values) -> { MatcherAssert.assertThat(params, Matchers.hasKey(key)); Assertions.assertArrayEquals(values.toArray(), params.get(key)); }); } ``` It uses `MatcherAssert` and `Matchers` from hamcrest (which we include already). I added another test case to test the combination of values for same keys. We could include other test methods from this class in this method, as many are doing the same thing with different input data. When doing so, we could either add the original bug reports as comments, or as input data. In the latter case, that data would be part of a failing test. -- 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: dev-unsubscr...@jmeter.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org