Skip to content

Commit 90e2394

Browse files
committed
Remove ThreadLocal in GraphQlArgumentBinderTests
1 parent 16a3dd2 commit 90e2394

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ class GraphQlArgumentBinderTests {
4545

4646
private final ObjectMapper mapper = new ObjectMapper();
4747

48-
private final ThreadLocal<GraphQlArgumentBinder> initializer =
49-
ThreadLocal.withInitial(() -> new GraphQlArgumentBinder(null));
48+
private final GraphQlArgumentBinder binder = new GraphQlArgumentBinder(null);
5049

5150

5251
@Test
5352
void defaultConstructor() throws Exception {
5453

55-
Object result = initializer.get().bind(
54+
Object result = this.binder.bind(
5655
environment("{\"key\":{\"name\":\"test\"}}"), "key",
5756
ResolvableType.forClass(SimpleBean.class));
5857

@@ -63,7 +62,7 @@ void defaultConstructor() throws Exception {
6362
@Test
6463
void defaultConstructorWithNestedBeanProperty() throws Exception {
6564

66-
Object result = initializer.get().bind(
65+
Object result = this.binder.bind(
6766
environment(
6867
"{\"key\":{" +
6968
"\"name\":\"test name\"," +
@@ -84,7 +83,7 @@ void defaultConstructorWithNestedBeanProperty() throws Exception {
8483
@Test
8584
void defaultConstructorWithNestedBeanListProperty() throws Exception {
8685

87-
Object result = initializer.get().bind(
86+
Object result = this.binder.bind(
8887
environment("{\"key\":{\"items\":[{\"name\":\"first\"},{\"name\":\"second\"}]}}"), "key",
8988
ResolvableType.forClass(ItemListHolder.class));
9089

@@ -96,7 +95,7 @@ void defaultConstructorWithNestedBeanListProperty() throws Exception {
9695
@Test // gh-301
9796
void defaultConstructorWithNestedBeanListEmpty() throws Exception {
9897

99-
Object result = initializer.get().bind(
98+
Object result = this.binder.bind(
10099
environment("{\"key\":{\"items\": []}}"), "key",
101100
ResolvableType.forClass(ItemListHolder.class));
102101

@@ -108,7 +107,7 @@ void defaultConstructorWithNestedBeanListEmpty() throws Exception {
108107
void defaultConstructorBindingError() {
109108

110109
assertThatThrownBy(
111-
() -> initializer.get().bind(
110+
() -> this.binder.bind(
112111
environment("{\"key\":{\"name\":\"test\",\"age\":\"invalid\"}}"), "key",
113112
ResolvableType.forClass(SimpleBean.class)))
114113
.extracting(ex -> ((BindException) ex).getFieldErrors())
@@ -123,7 +122,7 @@ void defaultConstructorBindingError() {
123122
@Test
124123
void primaryConstructor() throws Exception {
125124

126-
Object result = initializer.get().bind(
125+
Object result = this.binder.bind(
127126
environment("{\"key\":{\"name\":\"test\"}}"), "key",
128127
ResolvableType.forClass(PrimaryConstructorBean.class));
129128

@@ -134,7 +133,7 @@ void primaryConstructor() throws Exception {
134133
@Test
135134
void primaryConstructorWithBeanArgument() throws Exception {
136135

137-
Object result = initializer.get().bind(
136+
Object result = this.binder.bind(
138137
environment(
139138
"{\"key\":{" +
140139
"\"item\":{\"name\":\"Item name\"}," +
@@ -152,7 +151,7 @@ void primaryConstructorWithBeanArgument() throws Exception {
152151
@Test
153152
void primaryConstructorWithNestedBeanList() throws Exception {
154153

155-
Object result = initializer.get().bind(
154+
Object result = this.binder.bind(
156155
environment(
157156
"{\"key\":{\"items\":[" +
158157
"{\"name\":\"first\"}," +
@@ -168,7 +167,7 @@ void primaryConstructorWithNestedBeanList() throws Exception {
168167
@Test
169168
void primaryConstructorNotFound() {
170169
assertThatThrownBy(
171-
() -> initializer.get().bind(
170+
() -> this.binder.bind(
172171
environment("{\"key\":{\"name\":\"test\"}}"), "key",
173172
ResolvableType.forClass(NoPrimaryConstructorBean.class)))
174173
.isInstanceOf(IllegalStateException.class)
@@ -179,7 +178,7 @@ void primaryConstructorNotFound() {
179178
void primaryConstructorBindingError() {
180179

181180
assertThatThrownBy(
182-
() -> initializer.get().bind(
181+
() -> this.binder.bind(
183182
environment(
184183
"{\"key\":{" +
185184
"\"name\":\"Hello\"," +
@@ -205,7 +204,7 @@ void primaryConstructorBindingError() {
205204
void primaryConstructorBindingErrorWithNestedBeanList() {
206205

207206
assertThatThrownBy(
208-
() -> initializer.get().bind(
207+
() -> this.binder.bind(
209208
environment(
210209
"{\"key\":{\"items\":[" +
211210
"{\"name\":\"first\", \"age\":\"invalid\"}," +

0 commit comments

Comments
 (0)