milamberspace commented on code in PR #6872:
URL: https://github.com/apache/jmeter/pull/6872#discussion_r4731704095
##########
src/jorphan/src/test/java/org/apache/jorphan/collections/PackageTest.java:
##########
@@ -174,4 +177,41 @@ public void testSearch() throws Exception {
tree.traverse(searcher);
assertEquals(1, searcher.getSearchResults().size());
}
+
+ @Test
+ public void testTraverseCallbackOrder() {
+ // a has children b (with child c) and d.
+ ListedHashTree tree = new ListedHashTree();
+ tree.add("a", "b");
+ tree.getTree("a").getTree("b").add("c");
+ tree.getTree("a").add("d");
+ List<String> events = new ArrayList<>();
+ tree.traverse(new HashTreeTraverser() {
+ @Override
+ public void addNode(Object node, HashTree subTree) {
+ events.add("+" + node);
+ }
+
+ @Override
+ public void subtractNode() {
+ events.add("-");
+ }
+
+ @Override
+ public void processPath() {
+ events.add("path");
+ }
+ });
+ assertEquals(
+ Arrays.asList("+a", "+b", "+c", "path", "-", "-", "+d",
"path", "-", "-"),
+ events);
+ }
+
+ @Test
+ public void testHashCodeDiffersForDifferentTrees() {
+ HashTree leaf = new HashTree("abcde");
+ HashTree withChild = new HashTree("abcde");
+ withChild.add("abcde", "abcdef");
+ assertNotEquals(leaf.hashCode(), withChild.hashCode());
Review Comment:
Optional: different objects having different hash codes is not part of the
`hashCode` contract, so this test would fail on a legitimate rewrite of
`HashTree.hashCode()` that happens to collide for these two trees. It is
deterministic today, so fine to keep, but a short comment saying it guards
against a degenerate hash (for instance a constant) would make the intent clear.
##########
src/core/src/test/java/org/apache/jmeter/samplers/TestSampleResult.java:
##########
@@ -337,6 +338,90 @@ void testEncodingAndType() throws Exception {
Assertions.assertEquals("text", res.getDataType());
}
+ @Test
+ void testEncodingAndTypeEdgeCases() {
+ SampleResult res = new SampleResult();
+ res.setEncodingAndType("text/plain; charset=ISO-8859-1;
format=flowed");
+ Assertions.assertEquals("ISO-8859-1", res.getDataEncodingNoDefault());
+ res.setEncodingAndType("text/plain; charset='utf-16'");
+ Assertions.assertEquals("utf-16", res.getDataEncodingNoDefault());
+ res.setEncodingAndType("image/png");
+ Assertions.assertEquals(SampleResult.BINARY, res.getDataType());
+ res.setEncodingAndType("image/svg+xml");
+ Assertions.assertEquals(SampleResult.TEXT, res.getDataType());
+ }
+
+ @Test
+ void testIsBinaryType() {
+ Assertions.assertTrue(SampleResult.isBinaryType("image/png"));
+ Assertions.assertTrue(SampleResult.isBinaryType("audio/mpeg"));
+ Assertions.assertTrue(SampleResult.isBinaryType("video/mp4"));
+ // Media manifests and SVG are text, although their prefix looks
binary.
+ Assertions.assertFalse(SampleResult.isBinaryType("audio/mpegurl"));
+ Assertions.assertFalse(SampleResult.isBinaryType("audio/x-mpegurl"));
+ Assertions.assertFalse(SampleResult.isBinaryType("video/f4m"));
+ Assertions.assertFalse(SampleResult.isBinaryType("image/svg+xml"));
+ Assertions.assertFalse(SampleResult.isBinaryType("text/html"));
+ }
+
+ @Test
+ void testAddSubResultAddsSizesAndSharesThreadName() {
Review Comment:
Optional: this test checks four different behaviors (size totals, thread
name propagation, bytes-only totals, ignoring a `null` sub result). Splitting
it would make a failure easier to read.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]