Skip to content

Commit 3a278cc

Browse files
committed
Polishing
1 parent 6183f06 commit 3a278cc

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

spring-core/src/test/java/org/springframework/core/convert/support/ByteBufferConverterTests.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -33,57 +33,56 @@
3333
*/
3434
class ByteBufferConverterTests {
3535

36-
private GenericConversionService conversionService;
36+
private final GenericConversionService conversionService = new DefaultConversionService();
3737

3838

3939
@BeforeEach
4040
void setup() {
41-
this.conversionService = new DefaultConversionService();
42-
this.conversionService.addConverter(new ByteArrayToOtherTypeConverter());
43-
this.conversionService.addConverter(new OtherTypeToByteArrayConverter());
41+
conversionService.addConverter(new ByteArrayToOtherTypeConverter());
42+
conversionService.addConverter(new OtherTypeToByteArrayConverter());
4443
}
4544

4645

4746
@Test
48-
void byteArrayToByteBuffer() throws Exception {
47+
void byteArrayToByteBuffer() {
4948
byte[] bytes = new byte[] { 1, 2, 3 };
50-
ByteBuffer convert = this.conversionService.convert(bytes, ByteBuffer.class);
49+
ByteBuffer convert = conversionService.convert(bytes, ByteBuffer.class);
5150
assertThat(convert.array()).isNotSameAs(bytes);
5251
assertThat(convert.array()).isEqualTo(bytes);
5352
}
5453

5554
@Test
56-
void byteBufferToByteArray() throws Exception {
55+
void byteBufferToByteArray() {
5756
byte[] bytes = new byte[] { 1, 2, 3 };
5857
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
59-
byte[] convert = this.conversionService.convert(byteBuffer, byte[].class);
58+
byte[] convert = conversionService.convert(byteBuffer, byte[].class);
6059
assertThat(convert).isNotSameAs(bytes);
6160
assertThat(convert).isEqualTo(bytes);
6261
}
6362

6463
@Test
65-
void byteBufferToOtherType() throws Exception {
64+
void byteBufferToOtherType() {
6665
byte[] bytes = new byte[] { 1, 2, 3 };
6766
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
68-
OtherType convert = this.conversionService.convert(byteBuffer, OtherType.class);
67+
OtherType convert = conversionService.convert(byteBuffer, OtherType.class);
6968
assertThat(convert.bytes).isNotSameAs(bytes);
7069
assertThat(convert.bytes).isEqualTo(bytes);
7170
}
7271

7372
@Test
74-
void otherTypeToByteBuffer() throws Exception {
73+
void otherTypeToByteBuffer() {
7574
byte[] bytes = new byte[] { 1, 2, 3 };
7675
OtherType otherType = new OtherType(bytes);
77-
ByteBuffer convert = this.conversionService.convert(otherType, ByteBuffer.class);
76+
ByteBuffer convert = conversionService.convert(otherType, ByteBuffer.class);
7877
assertThat(convert.array()).isNotSameAs(bytes);
7978
assertThat(convert.array()).isEqualTo(bytes);
8079
}
8180

8281
@Test
83-
void byteBufferToByteBuffer() throws Exception {
82+
void byteBufferToByteBuffer() {
8483
byte[] bytes = new byte[] { 1, 2, 3 };
8584
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
86-
ByteBuffer convert = this.conversionService.convert(byteBuffer, ByteBuffer.class);
85+
ByteBuffer convert = conversionService.convert(byteBuffer, ByteBuffer.class);
8786
assertThat(convert).isNotSameAs(byteBuffer.rewind());
8887
assertThat(convert).isEqualTo(byteBuffer.rewind());
8988
assertThat(convert).isEqualTo(ByteBuffer.wrap(bytes));

spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
*/
5050
class CollectionToCollectionConverterTests {
5151

52-
private GenericConversionService conversionService = new GenericConversionService();
52+
private final GenericConversionService conversionService = new GenericConversionService();
5353

5454

5555
@BeforeEach
56-
void setUp() {
56+
void setup() {
5757
conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
5858
}
5959

spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java

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

3939
/**
4040
* @author Keith Donald
41-
* @author Phil Webb
41+
* @author Phillip Webb
4242
* @author Juergen Hoeller
4343
*/
4444
class MapToMapConverterTests {
@@ -47,7 +47,7 @@ class MapToMapConverterTests {
4747

4848

4949
@BeforeEach
50-
void setUp() {
50+
void setup() {
5151
conversionService.addConverter(new MapToMapConverter(conversionService));
5252
}
5353

spring-core/src/test/java/org/springframework/core/convert/support/ObjectToObjectConverterTests.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Optional;
2020

21+
import org.junit.jupiter.api.BeforeEach;
2122
import org.junit.jupiter.api.Test;
2223

2324
import org.springframework.core.convert.ConverterNotFoundException;
@@ -29,15 +30,19 @@
2930
* Unit tests for {@link ObjectToObjectConverter}.
3031
*
3132
* @author Sam Brannen
32-
* @author Phil Webb
33+
* @author Phillip Webb
3334
* @since 5.3.21
3435
* @see org.springframework.core.convert.converter.DefaultConversionServiceTests#convertObjectToObjectUsingValueOfMethod()
3536
*/
3637
class ObjectToObjectConverterTests {
3738

38-
private final GenericConversionService conversionService = new GenericConversionService() {{
39-
addConverter(new ObjectToObjectConverter());
40-
}};
39+
private final GenericConversionService conversionService = new GenericConversionService();
40+
41+
42+
@BeforeEach
43+
void setup() {
44+
conversionService.addConverter(new ObjectToObjectConverter());
45+
}
4146

4247

4348
/**
@@ -47,29 +52,29 @@ class ObjectToObjectConverterTests {
4752
@Test
4853
void nonStaticToTargetTypeSimpleNameMethodWithMatchingReturnType() {
4954
assertThat(conversionService.canConvert(Source.class, Data.class))
50-
.as("can convert Source to Data").isTrue();
55+
.as("can convert Source to Data").isTrue();
5156
Data data = conversionService.convert(new Source("test"), Data.class);
5257
assertThat(data).asString().isEqualTo("test");
5358
}
5459

5560
@Test
5661
void nonStaticToTargetTypeSimpleNameMethodWithDifferentReturnType() {
5762
assertThat(conversionService.canConvert(Text.class, Data.class))
58-
.as("can convert Text to Data").isFalse();
63+
.as("can convert Text to Data").isFalse();
5964
assertThat(conversionService.canConvert(Text.class, Optional.class))
60-
.as("can convert Text to Optional").isFalse();
65+
.as("can convert Text to Optional").isFalse();
6166
assertThatExceptionOfType(ConverterNotFoundException.class)
62-
.as("convert Text to Data")
63-
.isThrownBy(() -> conversionService.convert(new Text("test"), Data.class));
67+
.as("convert Text to Data")
68+
.isThrownBy(() -> conversionService.convert(new Text("test"), Data.class));
6469
}
6570

6671
@Test
6772
void staticValueOfFactoryMethodWithDifferentReturnType() {
6873
assertThat(conversionService.canConvert(String.class, Data.class))
69-
.as("can convert String to Data").isFalse();
74+
.as("can convert String to Data").isFalse();
7075
assertThatExceptionOfType(ConverterNotFoundException.class)
71-
.as("convert String to Data")
72-
.isThrownBy(() -> conversionService.convert("test", Data.class));
76+
.as("convert String to Data")
77+
.isThrownBy(() -> conversionService.convert("test", Data.class));
7378
}
7479

7580

@@ -84,9 +89,9 @@ private Source(String value) {
8489
public Data toData() {
8590
return new Data(this.value);
8691
}
87-
8892
}
8993

94+
9095
static class Text {
9196

9297
private final String value;
@@ -98,9 +103,9 @@ private Text(String value) {
98103
public Optional<Data> toData() {
99104
return Optional.of(new Data(this.value));
100105
}
101-
102106
}
103107

108+
104109
static class Data {
105110

106111
private final String value;
@@ -115,9 +120,8 @@ public String toString() {
115120
}
116121

117122
public static Optional<Data> valueOf(String string) {
118-
return (string != null) ? Optional.of(new Data(string)) : Optional.empty();
123+
return (string != null ? Optional.of(new Data(string)) : Optional.empty());
119124
}
120-
121125
}
122126

123127
}

0 commit comments

Comments
 (0)