diff --git a/metafix/src/main/java/org/metafacture/metafix/FixPath.java b/metafix/src/main/java/org/metafacture/metafix/FixPath.java index b6d90f5e..dcb424e9 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixPath.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixPath.java @@ -60,6 +60,7 @@ private FixPath(final String[] path) { } /*package-private*/ Value findIn(final Array array) { + final Value result; if (path.length > 0) { final String currentSegment = path[0]; @@ -92,6 +93,7 @@ else if (Value.isNumber(currentSegment)) { result = new Value(array); } return result; + } private Value findInValue(final Value value, final String[] p) { diff --git a/metafix/src/main/java/org/metafacture/metafix/Record.java b/metafix/src/main/java/org/metafacture/metafix/Record.java index a7dd5af3..852a22fd 100644 --- a/metafix/src/main/java/org/metafacture/metafix/Record.java +++ b/metafix/src/main/java/org/metafacture/metafix/Record.java @@ -232,4 +232,5 @@ public void transform(final String field, final BiConsumer { + i.startRecord("1"); + i.literal("title", "Aloha"); + i.literal("title", "Moin"); + i.literal("title", "Hey"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("title", "Aloha"); + o.get().literal("title", "Moin"); + o.get().literal("title", "Hey"); + o.get().endRecord(); + } ); } @@ -424,10 +438,24 @@ public void shouldIgnoreOptionsOnSubsequentLookupInExternalFileMap() { } @Test - @MetafixToDo("Lookup with unknown internal map should not touch record") public void shouldNotLookupInUnknownInternalMap() { - assertMap( - LOOKUP + " 'testMap')" + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + LOOKUP + " '" + CSV_MAP + "', sep_char:'\t')" + ), + i -> { + i.startRecord("1"); + i.literal("title", "Aloha"); + i.literal("title", "Moin"); + i.literal("title", "Hey"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("title", "Aloha"); + o.get().literal("title", "Moin"); + o.get().literal("title", "Hey"); + o.get().endRecord(); + } ); } diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index a6c8fced..00184ade 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -307,7 +307,7 @@ public void shouldNotTrimRepeatedField() { @Test // See https://github.com/metafacture/metafacture-fix/pull/133 - public void dontTrimStringInImplicitArrayOfHashes() { + public void shouldNotTrimStringInImplicitArrayOfHashes() { MetafixTestHelpers.assertThrowsCause(IllegalStateException.class, "Expected String, got Array", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "trim('data.title')" @@ -695,7 +695,7 @@ public void shouldAppendValueInEntireArray() { } @Test - public void appendValueToArray() { + public void shouldNotAppendValueToArray() { MetafixTestHelpers.assertThrowsCause(IllegalStateException.class, "Expected String, got Array", () -> MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( "append('animals[]', 'another one')" @@ -1149,30 +1149,24 @@ public void shouldPrependValueInArraySubField() { } @Test - @MetafixToDo("Like this? See also https://github.com/metafacture/metafacture-fix/issues/100") - public void shouldPrependValueToArray() { - MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "prepend('animals[]', 'the first one')" - ), - i -> { - i.startRecord("1"); - i.startEntity("animals[]"); - i.literal("1", "dog"); - i.literal("2", "cat"); - i.literal("3", "zebra"); - i.endEntity(); - i.endRecord(); - }, - o -> { - o.get().startRecord("1"); - o.get().startEntity("animals[]"); - o.get().literal("1", "the first one"); - o.get().literal("2", "dog"); - o.get().literal("3", "cat"); - o.get().literal("4", "zebra"); - o.get().endEntity(); - o.get().endRecord(); - } + // See https://github.com/metafacture/metafacture-fix/issues/100 + public void shouldNotPrependValueToArray() { + MetafixTestHelpers.assertThrowsCause(IllegalStateException.class, "Expected String, got Array", () -> + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "prepend('animals[]', 'the first one')" + ), + i -> { + i.startRecord("1"); + i.startEntity("animals[]"); + i.literal("1", "dog"); + i.literal("2", "cat"); + i.literal("3", "zebra"); + i.endEntity(); + i.endRecord(); + }, + o -> { + } + ) ); }