From 90e23945730d6b488578e008f0d9c0fbaf91e3b3 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Tue, 5 Jul 2022 07:15:01 +0100 Subject: [PATCH] Remove ThreadLocal in GraphQlArgumentBinderTests --- .../support/GraphQlArgumentBinderTests.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/GraphQlArgumentBinderTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/GraphQlArgumentBinderTests.java index 00f9cb63..ba942f06 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/GraphQlArgumentBinderTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/GraphQlArgumentBinderTests.java @@ -45,14 +45,13 @@ class GraphQlArgumentBinderTests { private final ObjectMapper mapper = new ObjectMapper(); - private final ThreadLocal initializer = - ThreadLocal.withInitial(() -> new GraphQlArgumentBinder(null)); + private final GraphQlArgumentBinder binder = new GraphQlArgumentBinder(null); @Test void defaultConstructor() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment("{\"key\":{\"name\":\"test\"}}"), "key", ResolvableType.forClass(SimpleBean.class)); @@ -63,7 +62,7 @@ class GraphQlArgumentBinderTests { @Test void defaultConstructorWithNestedBeanProperty() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment( "{\"key\":{" + "\"name\":\"test name\"," + @@ -84,7 +83,7 @@ class GraphQlArgumentBinderTests { @Test void defaultConstructorWithNestedBeanListProperty() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment("{\"key\":{\"items\":[{\"name\":\"first\"},{\"name\":\"second\"}]}}"), "key", ResolvableType.forClass(ItemListHolder.class)); @@ -96,7 +95,7 @@ class GraphQlArgumentBinderTests { @Test // gh-301 void defaultConstructorWithNestedBeanListEmpty() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment("{\"key\":{\"items\": []}}"), "key", ResolvableType.forClass(ItemListHolder.class)); @@ -108,7 +107,7 @@ class GraphQlArgumentBinderTests { void defaultConstructorBindingError() { assertThatThrownBy( - () -> initializer.get().bind( + () -> this.binder.bind( environment("{\"key\":{\"name\":\"test\",\"age\":\"invalid\"}}"), "key", ResolvableType.forClass(SimpleBean.class))) .extracting(ex -> ((BindException) ex).getFieldErrors()) @@ -123,7 +122,7 @@ class GraphQlArgumentBinderTests { @Test void primaryConstructor() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment("{\"key\":{\"name\":\"test\"}}"), "key", ResolvableType.forClass(PrimaryConstructorBean.class)); @@ -134,7 +133,7 @@ class GraphQlArgumentBinderTests { @Test void primaryConstructorWithBeanArgument() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment( "{\"key\":{" + "\"item\":{\"name\":\"Item name\"}," + @@ -152,7 +151,7 @@ class GraphQlArgumentBinderTests { @Test void primaryConstructorWithNestedBeanList() throws Exception { - Object result = initializer.get().bind( + Object result = this.binder.bind( environment( "{\"key\":{\"items\":[" + "{\"name\":\"first\"}," + @@ -168,7 +167,7 @@ class GraphQlArgumentBinderTests { @Test void primaryConstructorNotFound() { assertThatThrownBy( - () -> initializer.get().bind( + () -> this.binder.bind( environment("{\"key\":{\"name\":\"test\"}}"), "key", ResolvableType.forClass(NoPrimaryConstructorBean.class))) .isInstanceOf(IllegalStateException.class) @@ -179,7 +178,7 @@ class GraphQlArgumentBinderTests { void primaryConstructorBindingError() { assertThatThrownBy( - () -> initializer.get().bind( + () -> this.binder.bind( environment( "{\"key\":{" + "\"name\":\"Hello\"," + @@ -205,7 +204,7 @@ class GraphQlArgumentBinderTests { void primaryConstructorBindingErrorWithNestedBeanList() { assertThatThrownBy( - () -> initializer.get().bind( + () -> this.binder.bind( environment( "{\"key\":{\"items\":[" + "{\"name\":\"first\", \"age\":\"invalid\"}," +