You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@eventmesh.apache.org by "pandaapo (via GitHub)" <gi...@apache.org> on 2023/06/20 16:43:10 UTC
Re: [PR] [ISSUE #4138] Add Unit Test for UrlMappingPattern (eventmesh)
pandaapo commented on code in PR #4139:
URL: https://github.com/apache/eventmesh/pull/4139#discussion_r1235531431
##########
eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/util/UrlMappingPatternTest.java:
##########
@@ -86,8 +88,21 @@ public void testGetParamNames() {
}
@Test
- public void testCompile() {
- //TODO : Fix me to test the method compile(). It is better using Mockito not PowerMockito.
+ public void testCompile() throws NoSuchFieldException, IllegalAccessException {
+ // Mock the compiledUrlMappingPattern field with reflection
+ Pattern mockedPattern = mock(Pattern.class);
+ Field compiledUrlMappingPatternField = urlMappingPattern.getClass().getDeclaredField("compiledUrlMappingPattern");
+ compiledUrlMappingPatternField.setAccessible(true);
+ compiledUrlMappingPatternField.set(urlMappingPattern, mockedPattern);
Review Comment:
It seems unnecessary to `mock(Pattern.class)` for the field `compiledUrlMappingPattern` again. Because `compiledUrlMappingPattern` has already been mocked.
You can use reflection to obtain and directly use the `compiledUrlMappingPattern` field.
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org