justinmclean commented on code in PR #8133:
URL: https://github.com/apache/gravitino/pull/8133#discussion_r2290672699


##########
server/src/test/java/org/apache/gravitino/server/web/TestVersioningFilter.java:
##########
@@ -259,4 +259,21 @@ public void testGetHeaderNames() {
     assertTrue(actualHeaderNames.contains("Header2"));
     assertTrue(actualHeaderNames.contains("CustomHeader"));
   }
+
+  @Test
+  public void testDoFilterWithHeaderContainingValidVersionAsSubstring() throws 
Exception {
+    VersioningFilter filter = new VersioningFilter();
+    FilterChain mockChain = mock(FilterChain.class);
+    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
+    HttpServletResponse mockResponse = mock(HttpServletResponse.class);
+    when(mockRequest.getHeaders("Accept"))
+        .thenReturn(
+          new Vector<>(Collections.singletonList("foo 
application/vnd.gravitino.v1+json bar")).elements(),
+          new Vector<>(Collections.singletonList("foo 
application/vnd.gravitino.v2+json bar")).elements(),
+          new Vector<>(Collections.singletonList("foo 
application/vnd.gravitino.v3+json bar")).elements());
+
+    filter.doFilter(mockRequest, mockResponse, mockChain);
+    verify(mockChain).doFilter(any(), any());
+    verify(mockResponse).sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, 
"Unsupported version");
+  }
 }

Review Comment:
   There are a few issues with this test, I think. It contains contradictory 
verifications as you verify both chain.doFilter(..) and response.sendError(..), 
only one should happen for a single request.
   Stubbing getHeaders multiple times, means it returns a different enumeration 
on successive calls. You're probably only calling getHeaders once, so you’re 
not actually simulating returning 3 headers on one request. I'll take a look 
tomorrow in more detail.



-- 
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]

Reply via email to