2525
2626import java .time .Duration ;
2727import java .lang .reflect .Method ;
28+ import java .lang .reflect .InvocationTargetException ;
2829
2930import static org .mockito .Mockito .when ;
3031
@@ -90,14 +91,10 @@ public void parseRedisNodeInvalidInputs() throws Exception {
9091 parseMethod .setAccessible (true );
9192
9293 Assertions .assertAll (
93- () -> Assertions .assertThrows (IllegalArgumentException .class ,
94- () -> parseMethod .invoke (factory , "" )),
95- () -> Assertions .assertThrows (IllegalArgumentException .class ,
96- () -> parseMethod .invoke (factory , "[::1]:" )),
97- () -> Assertions .assertThrows (IllegalArgumentException .class ,
98- () -> parseMethod .invoke (factory , "localhost:70000" )),
99- () -> Assertions .assertThrows (IllegalArgumentException .class ,
100- () -> parseMethod .invoke (factory , "[]:6379" ))
94+ () -> assertInvalidNode (parseMethod , factory , "" ),
95+ () -> assertInvalidNode (parseMethod , factory , "[::1]:" ),
96+ () -> assertInvalidNode (parseMethod , factory , "localhost:70000" ),
97+ () -> assertInvalidNode (parseMethod , factory , "[]:6379" )
10198 );
10299 }
103100
@@ -107,4 +104,18 @@ private RedisConnectionFactory createFactoryWithDefaultUrl() {
107104 redisConfigProperties .setMode (RedisModeEnum .STANDALONE .getName ());
108105 return new RedisConnectionFactory (redisConfigProperties );
109106 }
107+
108+ private void assertInvalidNode (final Method parseMethod , final RedisConnectionFactory factory , final String url ) {
109+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
110+ try {
111+ parseMethod .invoke (factory , url );
112+ } catch (InvocationTargetException e ) {
113+ // unwrap to the original IllegalArgumentException
114+ if (e .getCause () instanceof RuntimeException ) {
115+ throw (RuntimeException ) e .getCause ();
116+ }
117+ throw new RuntimeException (e .getCause ());
118+ }
119+ });
120+ }
110121}
0 commit comments