Skip to content

Commit 1e3b0f1

Browse files
committed
fix tests
1 parent 5f211c1 commit 1e3b0f1

1 file changed

Lines changed: 23 additions & 38 deletions

File tree

src/test/java/it/aboutbits/springboot/toolbox/util/MapByIdentityTest.java

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import it.aboutbits.springboot.toolbox.type.identity.EntityId;
44
import it.aboutbits.springboot.toolbox.type.identity.Identified;
5+
import lombok.Getter;
56
import org.jspecify.annotations.NullMarked;
67
import org.junit.jupiter.api.Nested;
78
import org.junit.jupiter.api.Test;
@@ -19,8 +20,8 @@ class Of {
1920
@Test
2021
void collection() {
2122
// given
22-
var id1 = new TestEntityId(1);
23-
var id2 = new TestEntityId(2);
23+
var id1 = new TestEntity.ID(1L);
24+
var id2 = new TestEntity.ID(2L);
2425

2526
var entity1 = new TestEntity(id1);
2627
var entity2 = new TestEntity(id2);
@@ -39,8 +40,8 @@ void collection() {
3940
@Test
4041
void stream() {
4142
// given
42-
var id1 = new TestEntityId(1);
43-
var id2 = new TestEntityId(2);
43+
var id1 = new TestEntity.ID(1L);
44+
var id2 = new TestEntity.ID(2L);
4445

4546
var entity1 = new TestEntity(id1);
4647
var entity2 = new TestEntity(id2);
@@ -59,8 +60,8 @@ void stream() {
5960
@Test
6061
void streamable() {
6162
// given
62-
var id1 = new TestEntityId(1);
63-
var id2 = new TestEntityId(2);
63+
var id1 = new TestEntity.ID(1L);
64+
var id2 = new TestEntity.ID(2L);
6465

6566
var entity1 = new TestEntity(id1);
6667
var entity2 = new TestEntity(id2);
@@ -113,42 +114,26 @@ void emptyStreamable() {
113114
}
114115
}
115116

116-
private static class TestEntityId implements EntityId<Integer> {
117-
private final Integer value;
117+
@Getter
118+
private static class TestEntity implements Identified<TestEntity.ID> {
119+
private final ID id;
118120

119-
public TestEntityId(Integer value) {
120-
this.value = value;
121-
}
122-
123-
@Override
124-
public Integer value() {
125-
return value;
126-
}
127-
128-
@Override
129-
public int hashCode() {
130-
return value.hashCode();
131-
}
132-
133-
@Override
134-
public boolean equals(Object obj) {
135-
if (this == obj) return true;
136-
if (!(obj instanceof TestEntityId)) return false;
137-
var other = (TestEntityId) obj;
138-
return value.equals(other.value);
139-
}
140-
}
141-
142-
private static class TestEntity implements Identified<TestEntityId> {
143-
private final TestEntityId id;
144-
145-
public TestEntity(TestEntityId id) {
121+
TestEntity(ID id) {
146122
this.id = id;
147123
}
148124

149-
@Override
150-
public TestEntityId getId() {
151-
return id;
125+
public record ID(
126+
Long value
127+
) implements EntityId<Long>, Comparable<ID> {
128+
@Override
129+
public String toString() {
130+
return String.valueOf(value());
131+
}
132+
133+
@Override
134+
public int compareTo(ID other) {
135+
return Long.compare(this.value, other.value);
136+
}
152137
}
153138
}
154139
}

0 commit comments

Comments
 (0)