Skip to content

Commit

Permalink
remove unnecessary stubbing
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Azores <aazores@redhat.com>
  • Loading branch information
andrewazores committed Mar 21, 2023
1 parent aaa7ff2 commit 2cf3796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,13 @@ void shouldHaveExpectedRequiredPermissions() {

@Test
void shouldThrowIllegalStateExceptionOnUnknownNode() throws Exception {
when(env.getGraphQlContext()).thenReturn(graphCtx);
when(auth.validateHttpHeader(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(CompletableFuture.completedFuture(true));

UnknownNode source = Mockito.mock(UnknownNode.class);

when(env.getSource()).thenReturn(source);

IllegalStateException ex =
Assertions.assertThrows(IllegalStateException.class, () -> fetcher.get(env));
Assertions.assertThrows(
IllegalStateException.class, () -> fetcher.getAuthenticated(env));
MatcherAssert.assertThat(ex.getMessage(), Matchers.equalTo(source.getClass().toString()));
}

Expand All @@ -130,16 +127,14 @@ void shouldReturnSource() throws Exception {
HttpServerRequest req = Mockito.mock(HttpServerRequest.class);
when(ctx.request()).thenReturn(req);
when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
when(auth.validateHttpHeader(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(CompletableFuture.completedFuture(true));

TargetNode source = Mockito.mock(TargetNode.class);
ServiceRef sr = new ServiceRef("id1", URI.create("uri1"), "alias1");
when(source.getTarget()).thenReturn(sr);

when(env.getSource()).thenReturn(source);

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(nodes, Matchers.contains(source));
Expand All @@ -155,7 +150,6 @@ void shouldReturnTargetNodes() throws Exception {
DataFetchingEnvironmentImpl.newDataFetchingEnvironment(
Mockito.any(DataFetchingEnvironment.class)))
.thenReturn(builder);
when(env.getGraphQlContext()).thenReturn(graphCtx);
when(graphCtx.get(RoutingContext.class)).thenReturn(ctx);
HttpServerRequest req = Mockito.mock(HttpServerRequest.class);
when(ctx.request()).thenReturn(req);
Expand Down Expand Up @@ -213,7 +207,7 @@ void shouldReturnTargetNodes() throws Exception {
orphanNode,
orphanNode);

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(
Expand All @@ -235,7 +229,6 @@ void shouldReturnTargetNodeFiltered() throws Exception {
staticFilter
.when(() -> FilterInput.from(Mockito.any(DataFetchingEnvironment.class)))
.thenReturn(filter);
when(env.getGraphQlContext()).thenReturn(graphCtx);
when(graphCtx.get(RoutingContext.class)).thenReturn(ctx);
HttpServerRequest req = Mockito.mock(HttpServerRequest.class);
when(ctx.request()).thenReturn(req);
Expand Down Expand Up @@ -304,7 +297,7 @@ void shouldReturnTargetNodeFiltered() throws Exception {
orphanNode,
orphanNode);

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(nodes, Matchers.containsInAnyOrder(orphanNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,10 @@ void shouldReturnEmptyList() throws Exception {
staticEnv
.when(() -> DataFetchingEnvironmentImpl.newDataFetchingEnvironment(env))
.thenReturn(builder);
when(env.getGraphQlContext()).thenReturn(graphCtx);
when(auth.validateHttpHeader(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(CompletableFuture.completedFuture(true));

when(recurseFetcher.get(Mockito.any())).thenReturn(List.of());

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(nodes, Matchers.empty());
Expand Down Expand Up @@ -145,7 +142,7 @@ void shouldReturnTarget() throws Exception {

when(recurseFetcher.get(Mockito.any())).thenReturn(List.of(target));

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(nodes, Matchers.contains(target));
Expand Down Expand Up @@ -189,7 +186,7 @@ void shouldReturnTargetsFiltered() throws Exception {
when(recurseFetcher.get(Mockito.any()))
.thenReturn(List.of(target1, target2, target3));

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(nodes, Matchers.containsInAnyOrder(target1, target3));
Expand Down Expand Up @@ -274,7 +271,7 @@ void shouldReturnTargetsMultipleFilters() throws Exception {
when(recurseFetcher.get(Mockito.any()))
.thenReturn(List.of(target1, target2, target3));

List<TargetNode> nodes = fetcher.get(env);
List<TargetNode> nodes = fetcher.getAuthenticated(env);

MatcherAssert.assertThat(nodes, Matchers.notNullValue());
MatcherAssert.assertThat(nodes, Matchers.contains(target1));
Expand Down

0 comments on commit 2cf3796

Please sign in to comment.