|
1 | 1 | package org.jbehave.core.model;
|
2 | 2 |
|
| 3 | +import static java.util.Arrays.asList; |
3 | 4 | import static org.hamcrest.MatcherAssert.assertThat;
|
4 | 5 | import static org.hamcrest.Matchers.equalTo;
|
5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
6 | 7 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
7 | 8 | import static org.mockito.Mockito.mock;
|
8 | 9 | import static org.mockito.Mockito.when;
|
9 | 10 |
|
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.List; |
| 13 | +import java.util.Map; |
| 14 | + |
10 | 15 | import org.jbehave.core.io.LoadFromClasspath;
|
11 | 16 | import org.jbehave.core.io.ResourceLoader;
|
12 | 17 | import org.junit.jupiter.api.Test;
|
@@ -167,4 +172,25 @@ void shouldFailIfExamplesTableParsingSeparatorsArePlacesOutsideOfExternalTableTh
|
167 | 172 | + "external table they belong to:%n{%s=!}\ndata.table", separator);
|
168 | 173 | assertEquals(message, thrown.getMessage());
|
169 | 174 | }
|
| 175 | + |
| 176 | + @Test |
| 177 | + void shouldLoadTableFromPathAndPreserveSeparators() { |
| 178 | + // Given |
| 179 | + ExamplesTableFactory factory = new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()); |
| 180 | + |
| 181 | + // When |
| 182 | + ExamplesTable table = factory.createExamplesTable("data.table"); |
| 183 | + |
| 184 | + // Then |
| 185 | + assertThat(table.getHeaders(), equalTo(asList("symbol", "threshold", "price", "status"))); |
| 186 | + List<Map<String, String>> rows = table.getRows(); |
| 187 | + assertThat(rows.size(), equalTo(3)); |
| 188 | + ensureRowContentIs(rows, 0, asList("STK1", "15.0", "5.0", "OFF")); |
| 189 | + ensureRowContentIs(rows, 1, asList("STK1", "15.0", "10.0", "OFF")); |
| 190 | + ensureRowContentIs(rows, 2, asList("STK1", "15.0", "16.0", "ON")); |
| 191 | + } |
| 192 | + |
| 193 | + private void ensureRowContentIs(List<Map<String, String>> rows, int row, List<String> expected) { |
| 194 | + assertThat(new ArrayList<>(rows.get(row).values()), equalTo(expected)); |
| 195 | + } |
170 | 196 | }
|
0 commit comments