Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Add random unit tests from functional review. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jan 18, 2022
1 parent 3270490 commit e77188b
Showing 1 changed file with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,93 @@ public void shouldAddRandomNumber() {
);
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/100")
public void shouldReplaceExistingValueWithRandomNumber() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"random(others, '100')"
),
i -> {
i.startRecord("1");
i.literal("others", "human");
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().literal(ArgumentMatchers.eq("others"), ArgumentMatchers.argThat(i -> Integer.parseInt(i) < 100));
o.get().endRecord();
}
);
}

@Test
public void shouldAddRandomNumberToMarkedArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"random('animals[].$append', '100')"
),
i -> {
i.startRecord("1");
i.startEntity("animals[]");
i.literal("1", "cat");
i.literal("2", "dog");
i.endEntity();
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().startEntity("animals[]");
o.get().literal("1", "cat");
o.get().literal("2", "dog");
o.get().literal(ArgumentMatchers.eq("3"), ArgumentMatchers.argThat(i -> Integer.parseInt(i) < 100));
o.get().endEntity();
o.get().endRecord();
}
);
}

@Test
public void shouldAddObjectWithRandomNumberToMarkedArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"random('bnimals[].$append.number', '100')"
),
i -> {
i.startRecord("1");
i.endRecord();
},
(o, f) -> {
o.get().startRecord("1");
o.get().startEntity("bnimals[]");
o.get().startEntity("1");
o.get().literal(ArgumentMatchers.eq("number"), ArgumentMatchers.argThat(i -> Integer.parseInt(i) < 100));
f.apply(2).endEntity();
o.get().endRecord();
}
);
}

@Test
public void shouldAddRandomNumberToUnmarkedArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"random('animals.$append', '100')"
),
i -> {
i.startRecord("1");
i.literal("animals", "cat");
i.literal("animals", "dog");
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().startEntity("animals");
o.get().literal("1", "cat");
o.get().literal("2", "dog");
o.get().literal(ArgumentMatchers.eq("3"), ArgumentMatchers.argThat(i -> Integer.parseInt(i) < 100));
o.get().endEntity();
o.get().endRecord();
}
);
}

@Test
public void shouldRenameFieldsInHash() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
Expand Down

0 comments on commit e77188b

Please sign in to comment.