Skip to content

Commit 43c32dd

Browse files
committed
Replace use of deprecated methods in tests
1 parent 2c6ef91 commit 43c32dd

6 files changed

+26
-14
lines changed

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
import java.util.stream.Collectors;
2525
import java.util.stream.Stream;
2626

27-
import io.micrometer.context.ContextSnapshot;
27+
import io.micrometer.context.ContextSnapshotFactory;
2828
import org.junit.jupiter.params.ParameterizedTest;
2929
import org.junit.jupiter.params.provider.Arguments;
3030
import org.junit.jupiter.params.provider.MethodSource;
@@ -60,7 +60,7 @@ public class BatchMappingPrincipalMethodArgumentResolverTests extends BatchMappi
6060
ReactiveSecurityContextHolder.withAuthentication(this.authentication);
6161

6262
private final Function<Context, Context> threadLocalContextWriter = context ->
63-
ContextSnapshot.captureAll().updateContext(context);
63+
ContextSnapshotFactory.builder().build().captureAll().updateContext(context);
6464

6565

6666
private static Stream<Arguments> controllers() {

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323

2424
import graphql.GraphqlErrorBuilder;
2525
import io.micrometer.context.ContextSnapshot;
26+
import io.micrometer.context.ContextSnapshotFactory;
2627
import org.junit.jupiter.api.Nested;
2728
import org.junit.jupiter.api.Test;
2829
import org.junit.jupiter.params.ParameterizedTest;
@@ -70,8 +71,10 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests {
7071
private final Function<Context, Context> reactiveContextWriterWithoutAuthentication = context ->
7172
ReactiveSecurityContextHolder.withSecurityContext(Mono.just(SecurityContextHolder.createEmptyContext()));
7273

73-
private final Function<Context, Context> threadLocalContextWriter = context ->
74-
ContextSnapshot.captureAll().updateContext(context);
74+
private final Function<Context, Context> threadLocalContextWriter = context -> {
75+
ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll();
76+
return snapshot.updateContext(context);
77+
};
7578

7679
private final GreetingController greetingController = new GreetingController();
7780

spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
import graphql.GraphqlErrorBuilder;
2626
import io.micrometer.context.ContextRegistry;
2727
import io.micrometer.context.ContextSnapshot;
28+
import io.micrometer.context.ContextSnapshotFactory;
2829
import org.junit.jupiter.api.Test;
2930
import reactor.core.publisher.Flux;
3031
import reactor.core.publisher.Mono;
@@ -109,7 +110,8 @@ void resolveExceptionWithThreadLocal() {
109110
.toGraphQl();
110111

111112
ExecutionInput input = ExecutionInput.newExecutionInput(query).build();
112-
ContextSnapshot.captureAll().updateContext(input.getGraphQLContext());
113+
ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll();
114+
snapshot.updateContext(input.getGraphQLContext());
113115

114116
Flux<ResponseHelper> flux = Mono.defer(() -> Mono.fromFuture(graphQL.executeAsync(input)))
115117
.map(ResponseHelper::forSubscription)

spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import graphql.schema.idl.SchemaDirectiveWiringEnvironment;
3838
import io.micrometer.context.ContextRegistry;
3939
import io.micrometer.context.ContextSnapshot;
40+
import io.micrometer.context.ContextSnapshotFactory;
4041
import org.junit.jupiter.api.Test;
4142
import reactor.core.publisher.Flux;
4243
import reactor.core.publisher.Mono;
@@ -181,7 +182,8 @@ void dataFetcherWithThreadLocalContext() {
181182
.toGraphQl();
182183

183184
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
184-
ContextSnapshot.captureAll().updateContext(input.getGraphQLContext());
185+
ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll();
186+
snapshot.updateContext(input.getGraphQLContext());
185187

186188
Mono<ExecutionResult> resultMono = Mono.delay(Duration.ofMillis(10))
187189
.flatMap((aLong) -> Mono.fromFuture(graphQl.executeAsync(input)));
@@ -202,7 +204,7 @@ void dataFetcherDecoratedWithDataFetcherFactories() {
202204
@SuppressWarnings("unchecked")
203205
@Override
204206
public GraphQLFieldDefinition onField(SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition> env) {
205-
if (env.getDirective("UpperCase") != null) {
207+
if (env.getAppliedDirective("UpperCase") != null) {
206208
return env.setFieldDataFetcher(DataFetcherFactories.wrapDataFetcher(
207209
env.getFieldDataFetcher(),
208210
((dataFetchingEnv, value) -> {

spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import graphql.GraphqlErrorBuilder;
2525
import io.micrometer.context.ContextRegistry;
2626
import io.micrometer.context.ContextSnapshot;
27+
import io.micrometer.context.ContextSnapshotFactory;
2728
import org.junit.jupiter.api.Test;
2829
import reactor.core.publisher.Mono;
2930

@@ -100,7 +101,8 @@ void resolveExceptionWithThreadLocal() {
100101
.build());
101102

102103
resolver.setThreadLocalContextAware(true);
103-
ContextSnapshot.captureAll().updateContext(this.input.getGraphQLContext());
104+
ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll();
105+
snapshot.updateContext(this.input.getGraphQLContext());
104106

105107
Mono<ExecutionResult> result = Mono.delay(Duration.ofMillis(10)).flatMap((aLong) ->
106108
Mono.fromFuture(this.graphQlSetup.exceptionResolver(resolver).toGraphQl().executeAsync(this.input)));

spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandlerTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import io.micrometer.context.ContextRegistry;
3333
import io.micrometer.context.ContextSnapshot;
34+
import io.micrometer.context.ContextSnapshotFactory;
3435
import org.assertj.core.api.InstanceOfAssertFactories;
3536
import org.junit.jupiter.api.Test;
3637
import reactor.core.publisher.Flux;
@@ -403,7 +404,8 @@ void contextPropagation() throws Exception {
403404
GraphQlWebSocketHandler handler = initWebSocketHandler(threadLocalInterceptor);
404405

405406
// Ensure ContextSnapshot is present in WebSocketSession attributes
406-
this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.captureAll());
407+
ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll();
408+
this.session.getAttributes().put(ContextSnapshot.class.getName(), snapshot);
407409

408410
// Context should propagate, if message is handled on different thread
409411
Thread thread = new Thread(() -> {
@@ -452,7 +454,8 @@ private void handle(GraphQlWebSocketHandler handler, TextMessage... textMessages
452454

453455
if (!this.session.getAttributes().containsKey(ContextSnapshot.class.getName())) {
454456
// Ensure ContextSnapshot is present in WebSocketSession attributes
455-
this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.captureAll());
457+
ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll();
458+
this.session.getAttributes().put(ContextSnapshot.class.getName(), snapshot);
456459
}
457460

458461
for (TextMessage message : textMessages) {

0 commit comments

Comments
 (0)