From d8a9fd22c61c41a17def49e4cad7c8d954c14643 Mon Sep 17 00:00:00 2001 From: Uladzislau Arlouski Date: Wed, 6 Nov 2024 13:29:46 +0300 Subject: [PATCH] JBEHAVE-1531 Make separators properties accessible from outer transformers (#82) --- .../java/org/jbehave/core/model/ExamplesTableFactory.java | 6 +++++- .../jbehave/core/model/ExamplesTableFactoryBehaviour.java | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java b/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java index c9c8cda73..2daf1593a 100755 --- a/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java +++ b/jbehave-core/src/main/java/org/jbehave/core/model/ExamplesTableFactory.java @@ -99,6 +99,11 @@ public ExamplesTable createExamplesTable(String input) { String loadedTable = resourceLoader.loadResourceAsText(tableAsString.trim()); tablePropertiesQueue = tableParsers.parseProperties(loadedTable); Deque target = tablePropertiesQueue.getProperties(); + TableProperties headProperties = target.peekFirst(); + for (TableProperties outerProperties : properties) { + outerProperties.overrideSeparatorsFrom(headProperties); + target.addLast(outerProperties); + } boolean hasTransformers = target.getFirst().getTransformer() != null; if (hasTransformers) { @@ -115,7 +120,6 @@ public ExamplesTable createExamplesTable(String input) { target = tablePropertiesQueue.getProperties(); } } - properties.descendingIterator().forEachRemaining(target::addFirst); tablePropertiesQueue = new TablePropertiesQueue(tablePropertiesQueue.getTable(), target); } diff --git a/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java b/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java index 533d4e9cc..c46c507c8 100755 --- a/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java +++ b/jbehave-core/src/test/java/org/jbehave/core/model/ExamplesTableFactoryBehaviour.java @@ -145,8 +145,7 @@ void shouldLoadAndProperlyApplyTransformersForExamplesTableFromResourceInput() { // Then assertThat(examplesTable.asString(), equalTo( - innerTransformers - + lineFromFirstOuterTransformer + lineFromFirstOuterTransformer + lineFromSecondOuterTransformer + lineFromFirstInnerTransformer + lineFromSecondInnerTransformer)); @@ -179,7 +178,7 @@ void shouldLoadTableFromPathAndPreserveSeparators() { ExamplesTableFactory factory = new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()); // When - ExamplesTable table = factory.createExamplesTable("data.table"); + ExamplesTable table = factory.createExamplesTable("{transformer=FORMATTING}\ndata.table"); // Then assertThat(table.getHeaders(), equalTo(asList("symbol", "threshold", "price", "status")));