Skip to content

Commit 13413e0

Browse files
committed
feat: storing multiple properties for a set
1 parent 99c33c9 commit 13413e0

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/main/java/ru/ewc/spv/core/Storage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Storage {
3434
public void add(StoredValue specification) {
3535
this.specifications.add(
3636
new StoredValue(
37-
String.valueOf(++nextSetId),
37+
specification.set() == null ? String.valueOf(++nextSetId) : specification.set(),
3838
specification.property(),
3939
specification.value()
4040
)
@@ -49,4 +49,10 @@ public StoredValue get(String set) {
4949
.orElse(null);
5050
return storedValue;
5151
}
52+
53+
public List<StoredValue> getAsList(String set) {
54+
return this.specifications.stream()
55+
.filter(specification -> set.equals(specification.set()))
56+
.toList();
57+
}
5258
}

src/test/java/ru/ewc/spv/core/StorageTest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
public class StorageTest {
3232
@Test
3333
void shouldGetSetsWithSingleProperties() {
34-
final Storage actual = storageWith(
35-
new StoredValue(null, "Property", "Value"),
36-
new StoredValue(null, "NewProp", "NewValue")
37-
);
34+
final Storage actual = defaultStorage();
3835
MatcherAssert.assertThat(
3936
"The storage property for the first set should be fetched",
4037
actual.get("1"),
@@ -47,6 +44,28 @@ void shouldGetSetsWithSingleProperties() {
4744
);
4845
}
4946

47+
@Test
48+
void shouldGetSetWithMultipleProperties() {
49+
final Storage actual = defaultStorage();
50+
MatcherAssert.assertThat(
51+
"Should fetch all properties of a set",
52+
actual.getAsList("3"),
53+
Matchers.hasItems(
54+
new StoredValue("3", "Property", "ValueTheThird"),
55+
new StoredValue("3", "AnotherProp", "AnotherValue")
56+
)
57+
);
58+
}
59+
60+
private static Storage defaultStorage() {
61+
return storageWith(
62+
new StoredValue(null, "Property", "Value"),
63+
new StoredValue(null, "NewProp", "NewValue"),
64+
new StoredValue(null, "Property", "ValueTheThird"),
65+
new StoredValue("3", "AnotherProp", "AnotherValue")
66+
);
67+
}
68+
5069
private static Storage storageWith(StoredValue... specifications) {
5170
final Storage target = new Storage();
5271
for (StoredValue specification : specifications) {

0 commit comments

Comments
 (0)