Api { public static Stream<Route<AsyncHandler<Response<ByteString>>>> withCommonMiddleware( Stream<Route<AsyncHandler<Response<ByteString>>>> routes, RequestAuthenticator authenticator, String service) { return withCommonMiddleware(routes, Set::of, authenticator, service); } private  Api(); static Stream<Route<AsyncHandler<Response<ByteString>>>> prefixRoutes(
      Collection<Route<AsyncHandler<Response<ByteString>>>> routes,
      Version... versions); static Stream<Route<AsyncHandler<Response<ByteString>>>> withCommonMiddleware(
      Stream<Route<AsyncHandler<Response<ByteString>>>> routes,
      RequestAuthenticator authenticator,
      String service); static Stream<Route<AsyncHandler<Response<ByteString>>>> withCommonMiddleware(
      Stream<Route<AsyncHandler<Response<ByteString>>>> routes,
      Supplier<Set<String>> clientBlacklistSupplier,
      RequestAuthenticator authenticator,
      String service);  }
@Test @SuppressWarnings("unchecked") public void shouldHaveCorrectNumberOfMiddlewares() { when(route.withMiddleware(any(Middleware.class))).thenReturn(route); final List<Route<AsyncHandler<Response<ByteString>>>> originalRoutes = List.of(route); final List<Route<AsyncHandler<Response<ByteString>>>> routes = Api.withCommonMiddleware(originalRoutes.stream(), requestAuthenticator, "test").collect(toList()); verify(route, times(5)).withMiddleware(any(Middleware.class)); assertThat(routes, is(originalRoutes)); }