Skip to content

Commit 642f9b0

Browse files
committed
Add unit tests for array wildcards.
(Might be more suitable as `FixPathTest`s.)
1 parent dad2308 commit 642f9b0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

metafix/src/test/java/org/metafacture/metafix/HashValueTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
import nl.jqno.equalsverifier.EqualsVerifier;
2222
import org.junit.jupiter.api.Assertions;
2323
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.extension.ExtendWith;
2425

2526
import java.util.Arrays;
2627

28+
@ExtendWith(MetafixToDo.Extension.class)
2729
public class HashValueTest {
2830

2931
private static final String FIELD = "field";
@@ -383,6 +385,42 @@ public void shouldIterateOverFieldValuePairs() {
383385
);
384386
}
385387

388+
private void shouldFindArray(final String field) {
389+
final Value.Hash hash = newHash();
390+
hash.put(FIELD, Value.newArray(a -> a.add(VALUE)));
391+
392+
Assertions.assertEquals(VALUE, new FixPath(String.join(".", FIELD, field)).findIn(hash));
393+
}
394+
395+
@Test
396+
public void shouldFindArrayIndex() {
397+
shouldFindArray("1");
398+
}
399+
400+
@Test
401+
@MetafixToDo("Expected String, got Array")
402+
public void shouldFindArrayWildcard() {
403+
shouldFindArray("$last");
404+
}
405+
406+
private void shouldFindArraySubfield(final String field) {
407+
final Value.Hash hash = newHash();
408+
hash.put(FIELD, Value.newArray(a -> a.add(Value.newHash(h -> h.put(OTHER_FIELD, OTHER_VALUE)))));
409+
410+
Assertions.assertEquals(OTHER_VALUE, new FixPath(String.join(".", FIELD, field, OTHER_FIELD)).findIn(hash));
411+
}
412+
413+
@Test
414+
public void shouldFindArrayIndexSubfield() {
415+
shouldFindArraySubfield("1");
416+
}
417+
418+
@Test
419+
@MetafixToDo("Expected String, got Array")
420+
public void shouldFindArrayWildcardSubfield() {
421+
shouldFindArraySubfield("$last");
422+
}
423+
386424
private Value.Hash newHash() {
387425
return Value.newHash().asHash();
388426
}

0 commit comments

Comments
 (0)