Skip to content

Commit 4214e91

Browse files
committed
Polish
- Fix warnings in tests. Signed-off-by: Marten Deinum <mdeinum@gmail.com>
1 parent 83baf1d commit 4214e91

2 files changed

Lines changed: 17 additions & 22 deletions

File tree

spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/AbstractExcelItemReader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.springframework.beans.factory.InitializingBean;
3131
import org.springframework.core.io.Resource;
3232
import org.springframework.util.Assert;
33-
import org.springframework.util.ClassUtils;
3433

3534
/**
3635
* {@link org.springframework.batch.infrastructure.item.ItemReader} implementation to read an Excel file.
@@ -80,7 +79,6 @@ public abstract class AbstractExcelItemReader<T> extends AbstractItemCountingIte
8079

8180
public AbstractExcelItemReader() {
8281
super();
83-
this.setName(ClassUtils.getShortName(this.getClass()));
8482
}
8583

8684
@Override

spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/mapping/BeanWrapperRowMapperTests.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.batch.extensions.excel.mapping;
1818

1919
import java.util.ArrayList;
20-
import java.util.List;
2120

2221
import org.assertj.core.api.Assertions;
2322
import org.assertj.core.api.SoftAssertions;
@@ -26,12 +25,11 @@
2625
import org.springframework.batch.extensions.excel.MockSheet;
2726
import org.springframework.batch.extensions.excel.Player;
2827
import org.springframework.batch.extensions.excel.support.rowset.DefaultRowSetFactory;
29-
import org.springframework.batch.extensions.excel.support.rowset.RowSet;
30-
import org.springframework.context.ApplicationContext;
3128
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3229
import org.springframework.context.annotation.Bean;
3330
import org.springframework.context.annotation.Configuration;
3431
import org.springframework.context.annotation.Scope;
32+
import org.springframework.core.ParameterizedTypeReference;
3533

3634
/**
3735
* @author Marten Deinum
@@ -42,29 +40,29 @@ class BeanWrapperRowMapperTests {
4240
@Test
4341
void givenNoNameWhenInitCompleteThenIllegalStateShouldOccur() {
4442
Assertions.assertThatThrownBy(() -> {
45-
BeanWrapperRowMapper<Player> mapper = new BeanWrapperRowMapper<>();
43+
var mapper = new BeanWrapperRowMapper<Player>();
4644
mapper.afterPropertiesSet();
4745
}).isInstanceOf(IllegalStateException.class);
4846
}
4947

5048
@Test
5149
void givenAValidRowWhenMappingThenAValidPlayerShouldBeConstructed() throws Exception {
52-
BeanWrapperRowMapper<Player> mapper = new BeanWrapperRowMapper<>();
50+
var mapper = new BeanWrapperRowMapper<Player>();
5351
mapper.setTargetType(Player.class);
5452
mapper.afterPropertiesSet();
5553

56-
List<String[]> rows = new ArrayList<>();
54+
var rows = new ArrayList<String[]>();
5755
rows.add(new String[] { "id", "lastName", "firstName", "position", "birthYear", "debutYear" });
5856
rows.add(new String[] { "AbduKa00", "Abdul-Jabbar", "Karim", "rb", "1974", "1996" });
5957
MockSheet sheet = new MockSheet("players", rows);
6058

61-
RowSet rs = new DefaultRowSetFactory().create(sheet);
59+
var rs = new DefaultRowSetFactory().create(sheet);
6260
rs.next();
6361
rs.next();
6462

65-
Player p = mapper.mapRow(rs);
63+
var p = mapper.mapRow(rs);
6664

67-
SoftAssertions softly = new SoftAssertions();
65+
var softly = new SoftAssertions();
6866
softly.assertThat(p).isNotNull();
6967
softly.assertThat(p.getId()).isEqualTo("AbduKa00");
7068
softly.assertThat("Abdul-Jabbar").isEqualTo(p.getLastName());
@@ -80,20 +78,21 @@ void givenAValidRowWhenMappingThenAValidPlayerShouldBeConstructed() throws Excep
8078
@Test
8179
void givenAValidRowWhenMappingThenAValidPlayerShouldBeConstructedBasedOnPrototype() throws Exception {
8280

83-
ApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfig.class);
84-
BeanWrapperRowMapper<Player> mapper = ctx.getBean("playerRowMapper", BeanWrapperRowMapper.class);
81+
var ctx = new AnnotationConfigApplicationContext(TestConfig.class);
82+
var mapper = ctx.getBeanProvider(new ParameterizedTypeReference<BeanWrapperRowMapper<Player>>() {
83+
}).getIfAvailable();
8584

86-
List<String[]> rows = new ArrayList<>();
85+
var rows = new ArrayList<String[]>();
8786
rows.add(new String[] { "id", "lastName", "firstName", "position", "birthYear", "debutYear" });
8887
rows.add(new String[] { "AbduKa00", "Abdul-Jabbar", "Karim", "rb", "1974", "1996" });
8988
MockSheet sheet = new MockSheet("players", rows);
9089

91-
RowSet rs = new DefaultRowSetFactory().create(sheet);
90+
var rs = new DefaultRowSetFactory().create(sheet);
9291
rs.next();
9392
rs.next();
94-
Player p = mapper.mapRow(rs);
93+
var p = mapper.mapRow(rs);
9594

96-
SoftAssertions softly = new SoftAssertions();
95+
var softly = new SoftAssertions();
9796
softly.assertThat(p).isNotNull();
9897
softly.assertThat(p.getId()).isEqualTo("AbduKa00");
9998
softly.assertThat("Abdul-Jabbar").isEqualTo(p.getLastName());
@@ -111,19 +110,17 @@ public static class TestConfig {
111110

112111
@Bean
113112
public BeanWrapperRowMapper<Player> playerRowMapper() {
114-
BeanWrapperRowMapper<Player> mapper = new BeanWrapperRowMapper<>();
113+
var mapper = new BeanWrapperRowMapper<Player>();
115114
mapper.setPrototypeBeanName("player");
116115
return mapper;
117116
}
118117

119118
@Bean
120119
@Scope("prototype")
121120
public Player player() {
122-
Player p = new Player();
121+
var p = new Player();
123122
p.setComment("comment from context");
124123
return p;
125124
}
126-
127125
}
128-
129126
}

0 commit comments

Comments
 (0)