Skip to content

Commit

Permalink
Direction は @SliceableDefault の default 値を null にしない限り not null 項目とする
Browse files Browse the repository at this point in the history
  • Loading branch information
katagiri-kazumune committed Oct 25, 2020
1 parent bc4438e commit 56b0195
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ public Object resolveArgument(MethodParameter methodParameter, ModelAndViewConta
// Limit upper bound
pageSize = pageSize > maxPageSize ? maxPageSize : pageSize;

Direction direction = Direction.fromOptionalString(directionString).orElse(null);
// Direction の優先度は
// 1. パラメータの direction
// 2. @SliceableDefault の direction
Direction direction = Direction.fromOptionalString(directionString).orElse(defaultOrFallback.getDirection());

Integer pageNumber =
defaultOrFallback.getPageNumber() != null ? defaultOrFallback.getPageNumber() : DEFAULT_PAGE_NUMBER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testDefaultHandlerWithSizeParameter() throws Exception {
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(0, null, 123);
Sliceable expected = new SliceRequest(0, Direction.ASC, 123);
assertThat(actualSliceable, is(expected));
}

Expand All @@ -202,7 +202,7 @@ public void testDefaultHandlerWithValueWithSizeParameter() throws Exception {
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(0, null, 123);
Sliceable expected = new SliceRequest(0, Direction.ASC, 123);
assertThat(actualSliceable, is(expected));
}

Expand Down Expand Up @@ -246,7 +246,7 @@ public void testDefaultHandlerWithExceededSizeParameter() throws Exception {
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(0, null, 2000); // 2000 を超えないこと
Sliceable expected = new SliceRequest(0, Direction.ASC, 2000); // 2000 を超えないこと
assertThat(actualSliceable, is(expected));
}

Expand Down Expand Up @@ -312,7 +312,7 @@ public void testDefaultHandlerWithIllegalSizeParameter() throws Exception {
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(0, null, 10); // 強制的に 10
Sliceable expected = new SliceRequest(0, Direction.ASC, 10); // 強制的に 10
assertThat(actualSliceable, is(expected));
}

Expand All @@ -334,7 +334,7 @@ public void testDefaultHandlerWithValueWithIllegalSizeParameter() throws Excepti
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(0, null, 123); // 強制的に default 値
Sliceable expected = new SliceRequest(0, Direction.ASC, 123); // 強制的に default 値
assertThat(actualSliceable, is(expected));
}

Expand Down Expand Up @@ -542,6 +542,28 @@ public void testDefaultHandlerWithFullValue_WithParameter() throws Exception {
assertThat(actualSliceable, is(expected));
}

@Test
public void testDefaultHandlerWithFullValue_WithOneParameter() throws Exception {
// setup
Method method = getClass().getMethod("defaultHandlerWithFullValue", Sliceable.class);
MethodParameter methodParametere = new MethodParameter(method, 0);
ModelAndViewContainer mavContainer = mock(ModelAndViewContainer.class);
NativeWebRequest webRequest = mock(NativeWebRequest.class);
when(webRequest.getParameter(eq("page_number"))).thenReturn("1");
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);

// exercise
Object actual = sut.resolveArgument(methodParametere, mavContainer, webRequest, binderFactory);

// verify
assertThat(actual, is(notNullValue()));
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(1, Direction.DESC, 10);
assertThat(actualSliceable, is(expected));
}

@Test
public void testDefaultHandlerWithFullValue_WithInvalidParameter() throws Exception {
// setup
Expand All @@ -562,7 +584,7 @@ public void testDefaultHandlerWithFullValue_WithInvalidParameter() throws Except
assertThat(actual, is(instanceOf(Sliceable.class)));
Sliceable actualSliceable = (Sliceable) actual;

Sliceable expected = new SliceRequest(2, null, 10);
Sliceable expected = new SliceRequest(2, Direction.DESC, 10);
assertThat(actualSliceable, is(expected));
}
}

0 comments on commit 56b0195

Please sign in to comment.