Skip to content

Commit 03a4362

Browse files
committed
tried to improve readability
1 parent 3c9dd46 commit 03a4362

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/AggregatePathAssertions.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public AggregatePathAssertions hasPath(String expectedPath) {
4343
return this;
4444
}
4545

46-
/**
47-
* Example custom assertion method: Checks if the AggregatePath is empty.
48-
*/
4946
public AggregatePathAssertions isRoot() {
5047
isNotNull();
5148

@@ -55,6 +52,15 @@ public AggregatePathAssertions isRoot() {
5552
return this;
5653
}
5754

55+
public AggregatePathAssertions isNotRoot() {
56+
isNotNull();
57+
58+
if (actual.isRoot()) {
59+
failWithMessage("Expected AggregatePath not to be root path, but it was.");
60+
}
61+
return this;
62+
}
63+
5864
/**
5965
* Example custom assertion method: Validates the depth of the path.
6066
*/

spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/AggregatePathSoftAssertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public AggregatePathAssertions assertAggregatePath(AggregatePath actual) {
2525
return proxy(AggregatePathAssertions.class, AggregatePath.class, actual);
2626
}
2727

28-
static void assertNewSoftly(Consumer<AggregatePathSoftAssertions> softly) {
28+
static void assertAggregatePathsSoftly(Consumer<AggregatePathSoftAssertions> softly) {
2929
SoftAssertionsProvider.assertSoftly(AggregatePathSoftAssertions.class, softly);
3030
}
3131
}

spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/DefaultAggregatePathUnitTests.java

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ void isNotRootForNonRootPath() {
5050

5151
AggregatePath path = context.getAggregatePath(context.getPersistentPropertyPath("entityId", DummyEntity.class));
5252

53-
assertThat(path.isRoot()).isFalse();
53+
AggregatePathAssertions.assertThat(path).isNotRoot();
5454
}
5555

5656
@Test // GH-1525
5757
void isRootForRootPath() {
5858

5959
AggregatePath path = context.getAggregatePath(entity);
6060

61-
assertThat(path.isRoot()).isTrue();
61+
AggregatePathAssertions.assertThat(path).isRoot();
6262
}
6363

6464
@Test // GH-1525
6565
void getParentPath() {
6666

67-
AggregatePathSoftAssertions.assertNewSoftly(softly -> {
67+
AggregatePathSoftAssertions.assertAggregatePathsSoftly(softly -> {
6868

6969
softly.assertAggregatePath(path("second.third2.value").getParentPath()).hasPath("second.third2");
7070
softly.assertAggregatePath(path("second.third2").getParentPath()).hasPath("second");
@@ -79,13 +79,13 @@ void getRequiredLeafEntity() {
7979

8080
assertSoftly(softly -> {
8181

82+
RelationalPersistentEntity<?> secondEntity = context.getRequiredPersistentEntity(Second.class);
83+
RelationalPersistentEntity<?> thirdEntity = context.getRequiredPersistentEntity(Third.class);
84+
8285
softly.assertThat(path().getRequiredLeafEntity()).isEqualTo(entity);
83-
softly.assertThat(path("second").getRequiredLeafEntity())
84-
.isEqualTo(context.getRequiredPersistentEntity(Second.class));
85-
softly.assertThat(path("second.third").getRequiredLeafEntity())
86-
.isEqualTo(context.getRequiredPersistentEntity(Third.class));
87-
softly.assertThat(path("secondList").getRequiredLeafEntity())
88-
.isEqualTo(context.getRequiredPersistentEntity(Second.class));
86+
softly.assertThat(path("second").getRequiredLeafEntity()).isEqualTo(secondEntity);
87+
softly.assertThat(path("second.third").getRequiredLeafEntity()).isEqualTo(thirdEntity);
88+
softly.assertThat(path("secondList").getRequiredLeafEntity()).isEqualTo(secondEntity);
8989

9090
softly.assertThatThrownBy(() -> path("secondList.third.value").getRequiredLeafEntity())
9191
.isInstanceOf(IllegalStateException.class);
@@ -96,17 +96,16 @@ void getRequiredLeafEntity() {
9696
@Test // GH-1525
9797
void idDefiningPath() {
9898

99-
assertSoftly(softly -> {
99+
AggregatePathSoftAssertions.assertAggregatePathsSoftly(softly -> {
100100

101-
softly.assertThat((Object) path("second.third2.value").getIdDefiningParentPath()).isEqualTo(path());
102-
softly.assertThat((Object) path("second.third.value").getIdDefiningParentPath()).isEqualTo(path());
103-
softly.assertThat((Object) path("secondList.third2.value").getIdDefiningParentPath()).isEqualTo(path());
104-
softly.assertThat((Object) path("secondList.third.value").getIdDefiningParentPath()).isEqualTo(path());
105-
softly.assertThat((Object) path("second2.third2.value").getIdDefiningParentPath()).isEqualTo(path());
106-
softly.assertThat((Object) path("second2.third.value").getIdDefiningParentPath()).isEqualTo(path());
107-
softly.assertThat((Object) path("withId.second.third2.value").getIdDefiningParentPath())
108-
.isEqualTo(path("withId"));
109-
softly.assertThat((Object) path("withId.second.third.value").getIdDefiningParentPath()).isEqualTo(path("withId"));
101+
softly.assertAggregatePath(path("second.third2.value").getIdDefiningParentPath()).isRoot();
102+
softly.assertAggregatePath(path("second.third.value").getIdDefiningParentPath()).isRoot();
103+
softly.assertAggregatePath(path("secondList.third2.value").getIdDefiningParentPath()).isRoot();
104+
softly.assertAggregatePath(path("secondList.third.value").getIdDefiningParentPath()).isRoot();
105+
softly.assertAggregatePath(path("second2.third2.value").getIdDefiningParentPath()).isRoot();
106+
softly.assertAggregatePath(path("second2.third.value").getIdDefiningParentPath()).isRoot();
107+
softly.assertAggregatePath(path("withId.second.third2.value").getIdDefiningParentPath()).hasPath("withId");
108+
softly.assertAggregatePath(path("withId.second.third.value").getIdDefiningParentPath()).hasPath("withId");
110109
});
111110
}
112111

@@ -187,13 +186,11 @@ void getQualifierColumnType() {
187186

188187
@Test // GH-1525
189188
void extendBy() {
189+
AggregatePathSoftAssertions.assertAggregatePathsSoftly(softly -> {
190190

191-
assertSoftly(softly -> {
192-
193-
softly.assertThat((Object) path().append(entity.getRequiredPersistentProperty("withId")))
194-
.isEqualTo(path("withId"));
195-
softly.assertThat((Object) path("withId").append(path("withId").getRequiredIdProperty()))
196-
.isEqualTo(path("withId.withIdId"));
191+
softly.assertAggregatePath(path().append(entity.getRequiredPersistentProperty("withId"))).hasPath("withId");
192+
softly.assertAggregatePath(path("withId").append(path("withId").getRequiredIdProperty()))
193+
.hasPath("withId.withIdId");
197194
});
198195
}
199196

@@ -248,11 +245,11 @@ void isMultiValued() {
248245
softly.assertThat(path("second").isMultiValued()).isFalse();
249246
softly.assertThat(path("second.third2").isMultiValued()).isFalse();
250247
softly.assertThat(path("secondList.third2").isMultiValued()).isTrue(); // this seems wrong as third2 is an
248+
251249
// embedded path into Second, held by
252250
// List<Second> (so the parent is
253251
// multi-valued but not third2).
254-
// TODO: This test fails because MultiValued considers parents.
255-
// softly.assertThat(path("secondList.third.value").isMultiValued()).isFalse();
252+
softly.assertThat(path("secondList.third.value").isMultiValued()).isTrue();
256253
softly.assertThat(path("secondList").isMultiValued()).isTrue();
257254
});
258255
}
@@ -457,8 +454,7 @@ void getRequiredPersistentPropertyPath() {
457454
});
458455
}
459456

460-
@Test
461-
// GH-1525
457+
@Test // GH-1525
462458
void getLength() {
463459

464460
assertSoftly(softly -> {
@@ -476,25 +472,24 @@ void getLength() {
476472
@Test // GH-574
477473
void getTail() {
478474

479-
assertSoftly(softly -> {
475+
AggregatePathSoftAssertions.assertAggregatePathsSoftly(softly -> {
480476

481-
softly.assertThat((Object) path().getTail()).isEqualTo(null);
482-
softly.assertThat((Object) path("second").getTail()).isEqualTo(null);
483-
softly.assertThat(path("second.third").getTail().toDotPath()).isEqualTo("third");
484-
softly.assertThat(path("second.third.value").getTail().toDotPath()).isEqualTo("third.value");
477+
softly.assertAggregatePath(path().getTail()).isNull();
478+
softly.assertAggregatePath(path("second").getTail()).isNull();
479+
softly.assertAggregatePath(path("second.third").getTail()).hasPath("third");
480+
softly.assertAggregatePath(path("second.third.value").getTail()).hasPath("third.value");
485481
});
486482
}
487483

488484
@Test // GH-74
489485
void append() {
490486

491-
assertSoftly(softly -> {
492-
// assert that( .... ) matches ("second")
493-
softly.assertThat(path("second").append(path()).toDotPath()).isEqualTo("second");
494-
softly.assertThat(path().append(path("second")).toDotPath()).isEqualTo("second");
495-
softly.assertThat(path().append(path("second.third")).toDotPath()).isEqualTo("second.third");
487+
AggregatePathSoftAssertions.assertAggregatePathsSoftly(softly -> {
488+
softly.assertAggregatePath(path("second").append(path())).hasPath("second");
489+
softly.assertAggregatePath(path().append(path("second"))).hasPath("second");
490+
softly.assertAggregatePath(path().append(path("second.third"))).hasPath("second.third");
496491
AggregatePath value = path("second.third.value").getTail().getTail();
497-
softly.assertThat(path("second.third").append(value).toDotPath()).isEqualTo("second.third.value");
492+
softly.assertAggregatePath(path("second.third").append(value)).hasPath("second.third.value");
498493
});
499494
}
500495

0 commit comments

Comments
 (0)