Skip to content

Commit dc86d5d

Browse files
Captain1653filiphr
authored andcommitted
Fix minor warnings in test packages java8stream and nestedbeans:
remove unnecessary generic types from collection, remove unnecessary throws from test methods, simplify equals in test dto
1 parent 281b792 commit dc86d5d

26 files changed

Lines changed: 88 additions & 82 deletions

processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import java.util.ArrayList;
1111
import java.util.Arrays;
12-
import java.util.EnumSet;
1312
import java.util.HashSet;
1413
import java.util.Set;
14+
import java.util.stream.Stream;
1515

1616
import org.junit.Test;
1717
import org.junit.runner.RunWith;
@@ -55,7 +55,7 @@ public void shouldReverseMapNullList() {
5555
@Test
5656
public void shouldMapList() {
5757
Source source = new Source();
58-
source.setStringStream( Arrays.asList( "Bob", "Alice" ).stream() );
58+
source.setStringStream( Stream.of( "Bob", "Alice" ) );
5959

6060
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
6161

@@ -66,7 +66,7 @@ public void shouldMapList() {
6666
@Test
6767
public void shouldMapListWithoutSetter() {
6868
Source source = new Source();
69-
source.setStringStream2( Arrays.asList( "Bob", "Alice" ).stream() );
69+
source.setStringStream2( Stream.of( "Bob", "Alice" ) );
7070

7171
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
7272

@@ -88,7 +88,7 @@ public void shouldReverseMapList() {
8888
@Test
8989
public void shouldMapArrayList() {
9090
Source source = new Source();
91-
source.setStringArrayStream( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ).stream() );
91+
source.setStringArrayStream( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ).stream() );
9292

9393
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
9494

@@ -99,7 +99,7 @@ public void shouldMapArrayList() {
9999
@Test
100100
public void shouldReverseMapArrayList() {
101101
Target target = new Target();
102-
target.setStringArrayList( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
102+
target.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) );
103103

104104
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
105105

@@ -110,7 +110,7 @@ public void shouldReverseMapArrayList() {
110110
@Test
111111
public void shouldMapSet() {
112112
Source source = new Source();
113-
source.setStringStreamToSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ).stream() );
113+
source.setStringStreamToSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ).stream() );
114114

115115
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
116116

@@ -121,7 +121,7 @@ public void shouldMapSet() {
121121
@Test
122122
public void shouldReverseMapSet() {
123123
Target target = new Target();
124-
target.setStringSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ) );
124+
target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) );
125125

126126
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
127127

@@ -132,7 +132,7 @@ public void shouldReverseMapSet() {
132132
@Test
133133
public void shouldMapListToCollection() {
134134
Source source = new Source();
135-
source.setIntegerStream( Arrays.asList( 1, 2 ).stream() );
135+
source.setIntegerStream( Stream.of( 1, 2 ) );
136136

137137
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
138138

@@ -154,7 +154,7 @@ public void shouldReverseMapListToCollection() {
154154
@Test
155155
public void shouldMapIntegerSetToStringSet() {
156156
Source source = new Source();
157-
source.setAnotherIntegerStream( new HashSet<Integer>( Arrays.asList( 1, 2 ) ).stream() );
157+
source.setAnotherIntegerStream( new HashSet<>( Arrays.asList( 1, 2 ) ).stream() );
158158

159159
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
160160

@@ -165,7 +165,7 @@ public void shouldMapIntegerSetToStringSet() {
165165
@Test
166166
public void shouldReverseMapIntegerSetToStringSet() {
167167
Target target = new Target();
168-
target.setAnotherStringSet( new HashSet<String>( Arrays.asList( "1", "2" ) ) );
168+
target.setAnotherStringSet( new HashSet<>( Arrays.asList( "1", "2" ) ) );
169169

170170
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
171171

@@ -176,7 +176,7 @@ public void shouldReverseMapIntegerSetToStringSet() {
176176
@Test
177177
public void shouldMapSetOfEnumToStringSet() {
178178
Source source = new Source();
179-
source.setColours( EnumSet.of( Colour.BLUE, Colour.GREEN ).stream() );
179+
source.setColours( Stream.of( Colour.BLUE, Colour.GREEN ) );
180180

181181
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
182182

@@ -187,7 +187,7 @@ public void shouldMapSetOfEnumToStringSet() {
187187
@Test
188188
public void shouldReverseMapSetOfEnumToStringSet() {
189189
Target target = new Target();
190-
target.setColours( new HashSet<String>( Arrays.asList( "BLUE", "GREEN" ) ) );
190+
target.setColours( new HashSet<>( Arrays.asList( "BLUE", "GREEN" ) ) );
191191

192192
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
193193

@@ -198,7 +198,7 @@ public void shouldReverseMapSetOfEnumToStringSet() {
198198
@Test
199199
public void shouldMapIntegerStreamToNumberSet() {
200200
Set<Number> numbers = SourceTargetMapper.INSTANCE
201-
.integerStreamToNumberSet( Arrays.asList( 123, 456 ).stream() );
201+
.integerStreamToNumberSet( Stream.of( 123, 456 ) );
202202

203203
assertThat( numbers ).isNotNull();
204204
assertThat( numbers ).containsOnly( 123, 456 );
@@ -207,7 +207,7 @@ public void shouldMapIntegerStreamToNumberSet() {
207207
@Test
208208
public void shouldMapNonGenericList() {
209209
Source source = new Source();
210-
source.setStringStream3( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ).stream() );
210+
source.setStringStream3( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ).stream() );
211211

212212
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
213213

processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ public boolean equals(Object obj) {
4141
}
4242
StringHolder other = (StringHolder) obj;
4343
if ( string == null ) {
44-
if ( other.string != null ) {
45-
return false;
46-
}
44+
return other.string == null;
4745
}
48-
else if ( !string.equals( other.string ) ) {
49-
return false;
46+
else {
47+
return string.equals( other.string );
5048
}
51-
return true;
5249
}
5350
}

processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.mapstruct.ap.test.java8stream.context;
77

8-
import java.util.Arrays;
98
import java.util.Collection;
109
import java.util.stream.Stream;
1110

@@ -26,25 +25,25 @@
2625
public class StreamWithContextTest {
2726

2827
@Test
29-
public void shouldApplyAfterMapping() throws Exception {
28+
public void shouldApplyAfterMapping() {
3029
Stream<String> stringStream = StreamWithContextMapper.INSTANCE.intStreamToStringStream(
31-
Arrays.asList( 1, 2, 3, 5 ).stream() );
30+
Stream.of( 1, 2, 3, 5 ) );
3231

3332
assertThat( stringStream ).containsOnly( "1", "2" );
3433
}
3534

3635
@Test
37-
public void shouldApplyBeforeMappingOnArray() throws Exception {
36+
public void shouldApplyBeforeMappingOnArray() {
3837
Integer[] integers = new Integer[] { 1, 3 };
3938
Stream<Integer> stringStream = StreamWithContextMapper.INSTANCE.arrayToStream( integers );
4039

4140
assertThat( stringStream ).containsOnly( 30, 3 );
4241
}
4342

4443
@Test
45-
public void shouldApplyBeforeAndAfterMappingOnCollection() throws Exception {
44+
public void shouldApplyBeforeAndAfterMappingOnCollection() {
4645
Collection<String> stringsStream = StreamWithContextMapper.INSTANCE.streamToCollection(
47-
Arrays.asList( 10, 20, 40 ).stream() );
46+
Stream.of( 10, 20, 40 ) );
4847

4948
assertThat( stringsStream ).containsOnly( "23", "10", "20", "40", "230" );
5049
}

processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static org.assertj.core.api.Assertions.assertThat;
99

1010
import java.util.ArrayList;
11-
import java.util.Arrays;
1211
import java.util.Collection;
1312
import java.util.HashSet;
1413
import java.util.List;
@@ -90,7 +89,7 @@ public void shouldUseDefaultImplementationForSortedSet() {
9089

9190
@Test
9291
public void shouldUseTargetParameterForMapping() {
93-
List<TargetFoo> target = new ArrayList<TargetFoo>();
92+
List<TargetFoo> target = new ArrayList<>();
9493
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter(
9594
target,
9695
createSourceFooStream()
@@ -147,7 +146,7 @@ public void shouldUseAndReturnTargetParameterForArrayMappingAndSmallerArray() {
147146

148147
@Test
149148
public void shouldUseAndReturnTargetParameterForMapping() {
150-
List<TargetFoo> target = new ArrayList<TargetFoo>();
149+
List<TargetFoo> target = new ArrayList<>();
151150
Iterable<TargetFoo> result =
152151
SourceTargetMapper.INSTANCE
153152
.sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooStream(), target );
@@ -172,6 +171,6 @@ private void assertResultList(Iterable<TargetFoo> fooIterable) {
172171
}
173172

174173
private Stream<SourceFoo> createSourceFooStream() {
175-
return Arrays.asList( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) ).stream();
174+
return Stream.of( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) );
176175
}
177176
}

processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10-
import java.util.Arrays;
1110
import java.util.List;
11+
import java.util.stream.Stream;
1212

1313
import org.junit.Test;
1414
import org.junit.runner.RunWith;
@@ -28,7 +28,7 @@ public class NoSetterStreamMappingTest {
2828
@Test
2929
public void compilesAndMapsCorrectly() {
3030
NoSetterSource source = new NoSetterSource();
31-
source.setListValues( Arrays.asList( "foo", "bar" ).stream() );
31+
source.setListValues( Stream.of( "foo", "bar" ) );
3232

3333
NoSetterTarget target = NoSetterMapper.INSTANCE.toTarget( source );
3434

@@ -37,7 +37,7 @@ public void compilesAndMapsCorrectly() {
3737
// now test existing instances
3838

3939
NoSetterSource source2 = new NoSetterSource();
40-
source2.setListValues( Arrays.asList( "baz" ).stream() );
40+
source2.setListValues( Stream.of( "baz" ) );
4141
List<String> originalCollectionInstance = target.getListValues();
4242

4343
NoSetterTarget target2 = NoSetterMapper.INSTANCE.toTargetWithExistingTarget( source2, target );

processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515
public class NoSetterTarget {
16-
private List<String> listValues = new ArrayList<String>();
16+
private List<String> listValues = new ArrayList<>();
1717

1818
public List<String> getListValues() {
1919
return listValues;

processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Target {
1414

1515
public List<TargetFoo> getFooListNoSetter() {
1616
if ( fooListNoSetter == null ) {
17-
fooListNoSetter = new ArrayList<TargetFoo>();
17+
fooListNoSetter = new ArrayList<>();
1818
}
1919
return fooListNoSetter;
2020
}

processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ public boolean equals(Object obj) {
4545
}
4646
TargetFoo other = (TargetFoo) obj;
4747
if ( name == null ) {
48-
if ( other.name != null ) {
49-
return false;
50-
}
48+
return other.name == null;
5149
}
52-
else if ( !name.equals( other.name ) ) {
53-
return false;
50+
else {
51+
return name.equals( other.name );
5452
}
55-
return true;
5653
}
5754

5855
@Override

processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10-
import java.util.Arrays;
10+
import java.util.stream.Stream;
1111

1212
import org.junit.Test;
1313
import org.junit.runner.RunWith;
@@ -23,7 +23,7 @@ public class StreamToNonIterableMappingTest {
2323
@Test
2424
public void shouldMapStringStreamToStringUsingCustomMapper() {
2525
Source source = new Source();
26-
source.setNames( Arrays.asList( "Alice", "Bob", "Jim" ).stream() );
26+
source.setNames( Stream.of( "Alice", "Bob", "Jim" ) );
2727
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
2828

2929
assertThat( target ).isNotNull();

processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public String stringListToString(Stream<String> strings) {
1616
}
1717

1818
public Stream<String> stringToStringList(String string) {
19-
return string == null ? null : Arrays.asList( string.split( "-" ) ).stream();
19+
return string == null ? null : Arrays.stream( string.split( "-" ) );
2020
}
2121
}

0 commit comments

Comments
 (0)