Skip to content

Commit 8ec736d

Browse files
authored
Merge pull request #187 from cbot59/bugfix/default-row-set
Fix DefaultRowSet implementation
2 parents b1e195b + 288c398 commit 8ec736d

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/support/rowset/DefaultRowSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Properties getProperties() {
7777
}
7878

7979
Properties props = new Properties();
80-
for (int i = 0; i < this.currentRow.length; i++) {
80+
for (int i = 0; i < names.length; i++) {
8181
String value = this.currentRow[i];
8282
if (value != null) {
8383
props.setProperty(names[i], value);

spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/streaming/StreamingXlsxMappingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class StreamingXlsxMappingTests {
3434

3535
@Test
3636
void readAndMapRowsUsingRowMapper() throws Exception {
37-
var columns = new String[] {"id", "position", "lastName", "firstName", "birthYear", "debutYear", "comment"};
37+
var columns = new String[] {"id", "position", "lastName", "firstName", "birthYear", "debutYear"};
3838
var rowSetFactory = new DefaultRowSetFactory();
3939
rowSetFactory.setColumnNameExtractor(new StaticColumnNameExtractor(columns));
4040

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2025-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.batch.extensions.excel.support.rowset;
18+
19+
import java.util.Arrays;
20+
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.batch.extensions.excel.MockSheet;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
class DefaultRowSetTests {
29+
30+
private DefaultRowSet rowSet;
31+
32+
@BeforeEach
33+
void setUp() {
34+
this.rowSet = new DefaultRowSet(new MockSheet(
35+
"Sheet1",
36+
Arrays.asList("col1a,col1b,col1c".split(","), "col2a,col2b,col2c".split(","), "col3a,col3b,col3c".split(","))
37+
), new RowSetMetaData() {
38+
@Override
39+
public String[] getColumnNames() {
40+
return new String[]{ "cola", "colb"};
41+
}
42+
43+
@Override
44+
public String getSheetName() {
45+
return "Sheet1";
46+
}
47+
});
48+
}
49+
50+
@Test
51+
void shouldReturnPropsSizeEqualsToMetadataColumns() {
52+
this.rowSet.next();
53+
var properties = this.rowSet.getProperties();
54+
55+
assertThat(properties.size()).isEqualTo(2);
56+
assertThat(properties.getProperty("cola")).isEqualTo("col1a");
57+
assertThat(properties.getProperty("colb")).isEqualTo("col1b");
58+
assertThat(properties.getProperty("colc")).isNull();
59+
}
60+
}

0 commit comments

Comments
 (0)