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.
1717package org .springframework .batch .extensions .excel .mapping ;
1818
1919import java .util .ArrayList ;
20- import java .util .List ;
2120
2221import org .assertj .core .api .Assertions ;
2322import org .assertj .core .api .SoftAssertions ;
2625import org .springframework .batch .extensions .excel .MockSheet ;
2726import org .springframework .batch .extensions .excel .Player ;
2827import org .springframework .batch .extensions .excel .support .rowset .DefaultRowSetFactory ;
29- import org .springframework .batch .extensions .excel .support .rowset .RowSet ;
30- import org .springframework .context .ApplicationContext ;
3128import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
3229import org .springframework .context .annotation .Bean ;
3330import org .springframework .context .annotation .Configuration ;
3431import 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