Skip to content

Commit 3d63891

Browse files
committed
Polishing
Closes gh-327
1 parent 4e63970 commit 3d63891

File tree

5 files changed

+86
-80
lines changed

5 files changed

+86
-80
lines changed

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ private DefaultEntityList(List<E> entity, String path, ResponseDelegate delegate
562562

563563
@Override
564564
@SuppressWarnings("unchecked")
565-
public EntityList<E> contains(E... elements) {
565+
public EntityList<E> contains(E... values) {
566566
doAssert(() -> {
567-
List<E> expected = Arrays.asList(elements);
567+
List<E> expected = Arrays.asList(values);
568568
AssertionErrors.assertTrue("List at path '" + getPath() + "' does not contain " + expected,
569569
getEntity().containsAll(expected));
570570
});
@@ -573,9 +573,9 @@ public EntityList<E> contains(E... elements) {
573573

574574
@Override
575575
@SuppressWarnings("unchecked")
576-
public EntityList<E> doesNotContain(E... elements) {
576+
public EntityList<E> doesNotContain(E... values) {
577577
doAssert(() -> {
578-
List<E> expected = Arrays.asList(elements);
578+
List<E> expected = Arrays.asList(values);
579579
AssertionErrors.assertTrue(
580580
"List at path '" + getPath() + "' should not have contained " + expected,
581581
!getEntity().containsAll(expected));
@@ -585,9 +585,9 @@ public EntityList<E> doesNotContain(E... elements) {
585585

586586
@Override
587587
@SuppressWarnings("unchecked")
588-
public EntityList<E> containsExactly(E... elements) {
588+
public EntityList<E> containsExactly(E... values) {
589589
doAssert(() -> {
590-
List<E> expected = Arrays.asList(elements);
590+
List<E> expected = Arrays.asList(values);
591591
AssertionErrors.assertTrue(
592592
"List at path '" + getPath() + "' should have contained exactly " + expected,
593593
getEntity().equals(expected));
@@ -603,18 +603,18 @@ public EntityList<E> hasSize(int size) {
603603
}
604604

605605
@Override
606-
public EntityList<E> hasSizeLessThan(int boundary) {
606+
public EntityList<E> hasSizeLessThan(int size) {
607607
doAssert(() -> AssertionErrors.assertTrue(
608-
"List at path '" + getPath() + "' should have size less than " + boundary,
609-
getEntity().size() < boundary));
608+
"List at path '" + getPath() + "' should have size less than " + size,
609+
getEntity().size() < size));
610610
return this;
611611
}
612612

613613
@Override
614-
public EntityList<E> hasSizeGreaterThan(int boundary) {
614+
public EntityList<E> hasSizeGreaterThan(int size) {
615615
doAssert(() -> AssertionErrors.assertTrue(
616-
"List at path '" + getPath() + "' should have size greater than " + boundary,
617-
getEntity().size() > boundary));
616+
"List at path '" + getPath() + "' should have size greater than " + size,
617+
getEntity().size() > size));
618618
return this;
619619
}
620620
}

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/GraphQlTester.java

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -208,78 +208,78 @@ interface Response extends Traversable {
208208
}
209209

210210
/**
211-
* Declare options available to assert data at a given path.
211+
* Options available to assert the response values at the current path.
212212
*/
213213
interface Path extends Traversable {
214214

215215
/**
216-
* Assert the given path exists, even if the value is {@code null}.
217-
* @return spec to assert the converted entity with
216+
* Verify the given path exists, even if the value is {@code null}.
217+
* @return the same {@code Path} spec for further assertions
218218
*/
219219
Path pathExists();
220220

221221
/**
222222
* Assert the given path does not {@link #pathExists() exist}.
223-
* @return spec to assert the converted entity with
223+
* @return the same {@code Path} spec for further assertions
224224
*/
225225
Path pathDoesNotExist();
226226

227227
/**
228228
* Assert a value exists at the given path where the value is any {@code non-null}
229229
* value, possibly an empty array or map.
230-
* @return spec to assert the converted entity with
230+
* @return the same {@code Path} spec for further assertions
231231
*/
232232
Path valueExists();
233233

234234
/**
235235
* Assert a value does not {@link #valueExists() exist} at the given path.
236-
* @return spec to assert the converted entity with
236+
* @return the same {@code Path} spec for further assertions
237237
*/
238238
Path valueDoesNotExist();
239239

240240
/**
241241
* Assert the value at the given path does exist but is empty as defined
242242
* in {@link org.springframework.util.ObjectUtils#isEmpty(Object)}.
243-
* @return spec to assert the converted entity with
243+
* @return the same {@code Path} spec for further assertions
244244
* @see org.springframework.util.ObjectUtils#isEmpty(Object)
245245
*/
246246
Path valueIsEmpty();
247247

248248
/**
249249
* Assert the value at the given path is not {@link #valueIsEmpty() empty}.
250-
* @return spec to assert the converted entity with
250+
* @return the same {@code Path} spec for further assertions
251251
*/
252252
Path valueIsNotEmpty();
253253

254254
/**
255255
* Convert the data at the given path to the target type.
256256
* @param entityType the type to convert to
257257
* @param <D> the target entity type
258-
* @return spec to assert the converted entity with
258+
* @return an {@code Entity} spec to verify the decoded value with
259259
*/
260260
<D> Entity<D, ?> entity(Class<D> entityType);
261261

262262
/**
263263
* Convert the data at the given path to the target type.
264264
* @param entityType the type to convert to
265265
* @param <D> the target entity type
266-
* @return spec to assert the converted entity with
266+
* @return an {@code Entity} spec to verify the decoded value with
267267
*/
268268
<D> Entity<D, ?> entity(ParameterizedTypeReference<D> entityType);
269269

270270
/**
271271
* Convert the data at the given path to a List of the target type.
272272
* @param elementType the type of element to convert to
273273
* @param <D> the target entity type
274-
* @return spec to assert the converted List of entities with
274+
* @return an {@code EntityList} spec to verify the decoded values with
275275
*/
276276
<D> EntityList<D> entityList(Class<D> elementType);
277277

278278
/**
279279
* Convert the data at the given path to a List of the target type.
280280
* @param elementType the type to convert to
281281
* @param <D> the target entity type
282-
* @return spec to assert the converted List of entities with
282+
* @return an {@code EntityList} spec to verify the decoded values with
283283
*/
284284
<D> EntityList<D> entityList(ParameterizedTypeReference<D> elementType);
285285

@@ -291,7 +291,7 @@ interface Path extends Traversable {
291291
* <a href="https://jsonassert.skyscreamer.org/">JSONassert</a> library on to be
292292
* on the classpath.
293293
* @param expectedJson the expected JSON
294-
* @return spec to specify a different path
294+
* @return {@code Traversable} spec to select a different path
295295
* @see org.springframework.test.util.JsonExpectationsHelper#assertJsonEqual(String,
296296
* String)
297297
*/
@@ -303,7 +303,7 @@ interface Path extends Traversable {
303303
* of formatting, along with lenient checking, e.g. extensible and non-strict
304304
* array ordering.
305305
* @param expectedJson the expected JSON
306-
* @return spec to specify a different path
306+
* @return {@code Traversable} spec to select a different path
307307
* @see org.springframework.test.util.JsonExpectationsHelper#assertJsonEqual(String,
308308
* String, boolean)
309309
*/
@@ -312,121 +312,114 @@ interface Path extends Traversable {
312312
}
313313

314314
/**
315-
* Declare options available to assert data converted to an entity.
315+
* Contains a decoded entity and provides options to assert it
316316
*
317317
* @param <D> the entity type
318-
* @param <S> the spec type, including subtypes
318+
* @param <S> the {@code Entity} spec type
319319
*/
320320
interface Entity<D, S extends Entity<D, S>> extends Traversable {
321321

322322
/**
323-
* Assert the converted entity equals the given Object.
324-
* @param expected the expected Object
325-
* @param <T> the spec type
326-
* @return the same spec for more assertions
323+
* Verify the decoded entity is equal to the given value.
324+
* @param expected the expected value
325+
* @return the {@code Entity} spec for further assertions
327326
*/
328327
<T extends S> T isEqualTo(Object expected);
329328

330329
/**
331-
* Assert the converted entity does not equal the given Object.
332-
* @param other the Object to check against
333-
* @param <T> the spec type
334-
* @return the same spec for more assertions
330+
* Verify the decoded entity is not equal to the given value.
331+
* @param other the value to check against
332+
* @return the {@code Entity} spec for further assertions
335333
*/
336334
<T extends S> T isNotEqualTo(Object other);
337335

338336
/**
339-
* Assert the converted entity is the same instance as the given Object.
340-
* @param expected the expected Object
341-
* @param <T> the spec type
342-
* @return the same spec for more assertions
337+
* Verify the decoded entity is the same instance as the given value.
338+
* @param expected the expected value
339+
* @return the {@code Entity} spec for further assertions
343340
*/
344341
<T extends S> T isSameAs(Object expected);
345342

346343
/**
347-
* Assert the converted entity is not the same instance as the given Object.
348-
* @param other the Object to check against
349-
* @param <T> the spec type
350-
* @return the same spec for more assertions
344+
* Verify the decoded entity is not the same instance as the given value.
345+
* @param other the value to check against
346+
* @return the {@code Entity} spec for further assertions
351347
*/
352348
<T extends S> T isNotSameAs(Object other);
353349

354350
/**
355-
* Assert the converted entity matches the given predicate.
356-
* @param predicate the expected Object
357-
* @param <T> the spec type
358-
* @return the same spec for more assertions
351+
* Verify the decoded entity matches the given predicate.
352+
* @param predicate the predicate to apply
353+
* @return the {@code Entity} spec for further assertions
359354
*/
360355
<T extends S> T matches(Predicate<D> predicate);
361356

362357
/**
363-
* Perform any assertions on the converted entity, e.g. via AssertJ.
364-
* @param consumer the consumer to inspect the entity with
365-
* @param <T> the spec type
366-
* @return the same spec for more assertions
358+
* Verify the entity with the given {@link Consumer}.
359+
* @param consumer the consumer to apply
360+
* @return the {@code Entity} spec for further assertions
367361
*/
368362
<T extends S> T satisfies(Consumer<D> consumer);
369363

370364
/**
371-
* Return the converted entity.
372-
* @return the converter entity
365+
* Return the decoded entity value(s).
373366
*/
374367
D get();
375368

376369
}
377370

378371
/**
379-
* Extension of {@link Entity} with options available to assert data converted to
380-
* a List of entities.
372+
* Contains a List of decoded entities and provides options to assert them.
381373
*
382374
* @param <E> the type of elements in the list
383375
*/
384376
interface EntityList<E> extends Entity<List<E>, EntityList<E>> {
385377

386378
/**
387-
* Assert the list contains the given elements.
388-
* @param elements values that are expected
389-
* @return the same spec for more assertions
379+
* Verify the list contains the given values, in any order.
380+
* @param values values that are expected
381+
* @return the {@code EntityList} spec for further assertions
390382
*/
391383
@SuppressWarnings("unchecked")
392-
EntityList<E> contains(E... elements);
384+
EntityList<E> contains(E... values);
393385

394386
/**
395-
* Assert the list does not contain the given elements.
396-
* @param elements values that are not expected
397-
* @return the same spec for more assertions
387+
* Verify the list does not contain the given values.
388+
* @param values the values that are not expected
389+
* @return the {@code EntityList} spec for further assertions
398390
*/
399391
@SuppressWarnings("unchecked")
400-
EntityList<E> doesNotContain(E... elements);
392+
EntityList<E> doesNotContain(E... values);
401393

402394
/**
403-
* Assert the list contains the given elements.
404-
* @param elements values that are expected
405-
* @return the same spec for more assertions
395+
* Verify that the list contains exactly the given values and nothing
396+
* else, in the same order.
397+
* @param values the expected values
398+
* @return the {@code EntityList} spec for further assertions
406399
*/
407400
@SuppressWarnings("unchecked")
408-
EntityList<E> containsExactly(E... elements);
401+
EntityList<E> containsExactly(E... values);
409402

410403
/**
411-
* Assert the list contains the specified number of elements.
412-
* @param size the number of elements expected
413-
* @return the same spec for more assertions
404+
* Verify the number of values in the list.
405+
* @param size the expected size
406+
* @return the {@code EntityList} spec for further assertions
414407
*/
415408
EntityList<E> hasSize(int size);
416409

417410
/**
418-
* Assert the list contains fewer elements than the specified number.
419-
* @param boundary the number to compare the number of elements to
420-
* @return the same spec for more assertions
411+
* Verify the list has fewer than the number of values.
412+
* @param size the number to compare the actual size to
413+
* @return the {@code EntityList} spec for further assertions
421414
*/
422-
EntityList<E> hasSizeLessThan(int boundary);
415+
EntityList<E> hasSizeLessThan(int size);
423416

424417
/**
425-
* Assert the list contains more elements than the specified number.
426-
* @param boundary the number to compare the number of elements to
427-
* @return the same spec for more assertions
418+
* Verify the list has more than the specified number of values.
419+
* @param size the number to compare the actual size to
420+
* @return the {@code EntityList} spec for further assertions
428421
*/
429-
EntityList<E> hasSizeGreaterThan(int boundary);
422+
EntityList<E> hasSizeGreaterThan(int size);
430423

431424
}
432425

spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ void entityList() {
138138
MovieCharacter leia = MovieCharacter.create("Leia Organa");
139139
MovieCharacter jabba = MovieCharacter.create("Jabba the Hutt");
140140

141-
List<MovieCharacter> actual = response.path("me.friends").entityList(MovieCharacter.class)
141+
GraphQlTester.EntityList<MovieCharacter> entityList =
142+
response.path("me.friends").entityList(MovieCharacter.class);
143+
144+
List<MovieCharacter> actual = entityList
142145
.contains(han)
143146
.containsExactly(han, leia)
144147
.doesNotContain(jabba)
@@ -149,6 +152,10 @@ void entityList() {
149152

150153
assertThat(actual).containsExactly(han, leia);
151154

155+
assertThatThrownBy(() -> entityList.containsExactly(leia, han))
156+
.as("Should be exactly the same order")
157+
.hasMessageStartingWith("List at path 'me.friends' should have contained exactly");
158+
152159
response.path("me.friends")
153160
.entityList(new ParameterizedTypeReference<MovieCharacter>() {})
154161
.containsExactly(han, leia);

spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/MovieCharacter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public int hashCode() {
5959
return (this.name != null) ? this.name.hashCode() : super.hashCode();
6060
}
6161

62+
@Override
63+
public String toString() {
64+
return "MovieCharacter[name='" + this.name + "']";
65+
}
66+
6267
}

spring-graphql/src/test/java/org/springframework/graphql/client/MovieCharacter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ public int hashCode() {
6363
public String toString() {
6464
return "MovieCharacter[name='" + this.name + "']";
6565
}
66+
6667
}

0 commit comments

Comments
 (0)