Skip to content

Commit

Permalink
Add xml to streaming generation
Browse files Browse the repository at this point in the history
  • Loading branch information
snuyanzin committed Dec 15, 2024
1 parent 74a4619 commit 3ee70b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/java/net/datafaker/transformations/Transformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ default Stream<OUT> generateStream(final Schema<IN, ?> schema, long limit) {
return Stream.generate(() -> {
StringBuilder res = new StringBuilder();
if (item.current == 0) {
res.append(getStartStream(schema)).append(getLineSeparator());
final String startStream = getStartStream(schema);
if (startStream != null) {
res.append(getStartStream(schema)).append(getLineSeparator());
}
}
res.append(apply(null, schema, item.current));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public CharSequence generate(Schema<IN, ?> schema, int limit) {

@Override
public String getStartStream(Schema<IN, ?> schema) {
throw new UnsupportedOperationException();
return null;
}

@Override
public String getEndStream() {
throw new UnsupportedOperationException();
return null;
}

public static class XmlTransformerBuilder<IN> {
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/net/datafaker/sequence/FakeStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.datafaker.transformations.JsonTransformer;
import net.datafaker.transformations.Schema;
import net.datafaker.transformations.Transformer;
import net.datafaker.transformations.XmlTransformer;
import net.datafaker.transformations.sql.SqlTransformer;
import org.assertj.core.util.Files;
import org.junit.jupiter.api.RepeatedTest;
Expand Down Expand Up @@ -371,6 +372,9 @@ void testCsvFilesCreated(final String testName, final Transformer transformer, f

private static Stream<Arguments> inputForFilesCreatedTest() {
return Stream.of(
Arguments.of("xml", new XmlTransformer.XmlTransformerBuilder().build(), List.of(
"<FirstName>Willis</FirstName><LastName>Huels</LastName>",
"<FirstName>Carlena</FirstName><LastName>Jenkins</LastName>")),
Arguments.of("csv", CsvTransformer.builder().build(), List.of(
"\"FirstName\";\"LastName\"",
"\"Willis\";\"Huels\"",
Expand Down

0 comments on commit 3ee70b3

Please sign in to comment.