Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Sep 9, 2024
1 parent 5c1ab7e commit 4e1756d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ private Model initModel() {

@Override
public DefaultRenderingBuilder status(HttpStatusCode status) {
if (this.view instanceof RedirectView) {
((RedirectView) this.view).setStatusCode(status);
if (this.view instanceof RedirectView redirectView) {
redirectView.setStatusCode(status);
}
else {
this.status = status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ void defaultValuesForRedirect() {
Rendering rendering = Rendering.redirectTo("abc").build();

Object view = rendering.view();
assertThat(view.getClass()).isEqualTo(RedirectView.class);
assertThat(((RedirectView) view).getUrl()).isEqualTo("abc");
assertThat(((RedirectView) view).isContextRelative()).isTrue();
assertThat(((RedirectView) view).isPropagateQuery()).isFalse();
assertThat(view).isExactlyInstanceOf(RedirectView.class);
RedirectView redirectView = (RedirectView) view;
assertThat(redirectView.getUrl()).isEqualTo("abc");
assertThat(redirectView.isContextRelative()).isTrue();
assertThat(redirectView.isPropagateQuery()).isFalse();
}


@Test
void viewName() {
Rendering rendering = Rendering.view("foo").build();

assertThat(rendering.view()).isEqualTo("foo");
}

Expand Down Expand Up @@ -114,7 +115,7 @@ void redirectWithAbsoluteUrl() {
Rendering rendering = Rendering.redirectTo("foo").contextRelative(false).build();

Object view = rendering.view();
assertThat(view.getClass()).isEqualTo(RedirectView.class);
assertThat(view).isExactlyInstanceOf(RedirectView.class);
assertThat(((RedirectView) view).isContextRelative()).isFalse();
}

Expand All @@ -123,17 +124,17 @@ void redirectWithPropagateQuery() {
Rendering rendering = Rendering.redirectTo("foo").propagateQuery(true).build();

Object view = rendering.view();
assertThat(view.getClass()).isEqualTo(RedirectView.class);
assertThat(view).isExactlyInstanceOf(RedirectView.class);
assertThat(((RedirectView) view).isPropagateQuery()).isTrue();
}

@Test // gh-33498
@Test // gh-33498
void redirectWithCustomStatus() {
HttpStatus status = HttpStatus.MOVED_PERMANENTLY;
Rendering rendering = Rendering.redirectTo("foo").status(status).build();

Object view = rendering.view();
assertThat(view.getClass()).isEqualTo(RedirectView.class);
assertThat(view).isExactlyInstanceOf(RedirectView.class);
assertThat(((RedirectView) view).getStatusCode()).isEqualTo(status);
}

Expand Down

0 comments on commit 4e1756d

Please sign in to comment.