11package io .jooby .internal ;
22
3+ import static org .mockito .Mockito .mock ;
4+
35import io .jooby .Context ;
4- import io .jooby .MockContext ;
56import io .jooby .Renderer ;
67import io .jooby .Route ;
78import io .jooby .Throwing ;
1112
1213import static org .junit .jupiter .api .Assertions .assertEquals ;
1314import static org .junit .jupiter .api .Assertions .assertTrue ;
15+ import static org .mockito .Mockito .when ;
1416
1517public class ChiTest {
1618
@@ -23,12 +25,19 @@ public void routeOverride() {
2325 router .insert (bar );
2426
2527 RouterMatch result = router
26- .find (new MockContext (). setPathString ("/abcd" ), Renderer .TO_STRING ,
28+ .find (ctx ("/abcd" ), Renderer .TO_STRING ,
2729 Collections .emptyList ());
2830 assertTrue (result .matches );
2931 assertEquals (bar , result .route ());
3032 }
3133
34+ private Context ctx (String path ) {
35+ Context context = mock (Context .class );
36+ when (context .pathString ()).thenReturn (path );
37+ when (context .getMethod ()).thenReturn ("GET" );
38+ return context ;
39+ }
40+
3241 @ Test
3342 public void routeCase () {
3443 $Chi router = new $Chi ();
@@ -39,7 +48,7 @@ public void routeCase() {
3948 router .insert (foos );
4049
4150 RouterMatch result = router
42- .find (new MockContext (). setPathString ("/abcd/" ), Renderer .TO_STRING ,
51+ .find (ctx ("/abcd/" ), Renderer .TO_STRING ,
4352 Collections .emptyList ());
4453 assertTrue (result .matches );
4554 assertEquals (foos , result .route ());
@@ -73,8 +82,9 @@ public void wildOnRoot() throws Exception {
7382 });
7483 }
7584
76- private void find ($Chi router , String pattern , Throwing .Consumer2 <Context , RouterMatch > consumer ) {
77- Context rootctx = new MockContext ().setPathString (pattern );
85+ private void find ($Chi router , String pattern ,
86+ Throwing .Consumer2 <Context , RouterMatch > consumer ) {
87+ Context rootctx = ctx (pattern );
7888 RouterMatch result = router
7989 .find (rootctx , Renderer .TO_STRING , Collections .emptyList ());
8090 consumer .accept (rootctx , result );
0 commit comments