Skip to content

Commit 1f8ce31

Browse files
committed
GP-64 refactor DateServletTest.java to support protected doGetMethod()
1 parent 1448394 commit 1f8ce31

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

2-0-servlet-api/2-0-1-hello-servlet-api/src/test/java/com/bobocode/DateServletTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.lang.reflect.InvocationTargetException;
1818
import java.lang.reflect.Method;
1919
import java.time.LocalDate;
20+
import java.util.Arrays;
2021
import java.util.Optional;
2122
import java.util.Set;
2223

@@ -108,7 +109,11 @@ void dateServletReturnsDateInResponse() throws IOException, NoSuchMethodExceptio
108109
}
109110

110111
private Method getDoGetMethod() throws NoSuchMethodException {
111-
return dateServletClass
112-
.getMethod("doGet", HttpServletRequest.class, HttpServletResponse.class);
112+
var method = Arrays.stream(dateServletClass.getDeclaredMethods())
113+
.filter(m -> m.getName().equals("doGet"))
114+
.findAny()
115+
.orElseThrow();
116+
method.setAccessible(true);
117+
return method;
113118
}
114119
}

0 commit comments

Comments
 (0)