11package io .avaje .jex .core ;
22
3- import io .avaje .jex .Jex ;
4- import org .junit .jupiter .api .AfterAll ;
5- import org .junit .jupiter .api .Test ;
3+ import static org .assertj .core .api .Assertions .assertThat ;
64
75import java .net .http .HttpResponse ;
86
9- import static org .assertj .core .api .Assertions .assertThat ;
7+ import org .junit .jupiter .api .AfterAll ;
8+ import org .junit .jupiter .api .Test ;
9+
10+ import io .avaje .jex .Jex ;
11+ import io .avaje .jex .http .NotFoundException ;
1012
1113class RedirectTest {
1214
@@ -26,6 +28,7 @@ static TestPair init() {
2628 .get ("/one" , ctx -> ctx .text ("one" ))
2729 .get ("/two" , ctx -> ctx .text ("two" ))
2830 .get ("/redirect/me" , ctx -> ctx .redirect ("/one?from=handler" ))
31+ .error (NotFoundException .class , (ctx , e ) -> ctx .redirect ("/one?from=error" ))
2932 .get ("/other/me" , ctx -> ctx .text ("never hit" )));
3033 return TestPair .create (app );
3134 }
@@ -42,6 +45,13 @@ void redirect_via_handler() {
4245 assertThat (res .statusCode ()).isEqualTo (200 );
4346 }
4447
48+ @ Test
49+ void redirect_via_error_handler () {
50+ HttpResponse <String > res = pair .request ().path ("redirect/error" ).GET ().asString ();
51+ assertThat (res .body ()).isEqualTo ("one" );
52+ assertThat (res .statusCode ()).isEqualTo (200 );
53+ }
54+
4555 @ Test
4656 void redirect_via_beforeHandler () {
4757 HttpResponse <String > res = pair .request ().path ("other/me" ).GET ().asString ();
0 commit comments