Skip to content

Commit 152cee7

Browse files
committed
DATACMNS-1718 - Migrate tests to JUnit 5.
1 parent 024f879 commit 152cee7

File tree

251 files changed

+2742
-2726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+2742
-2726
lines changed

src/test/java/SampleInterface.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.springframework.data.web.ProxyingHandlerMethodArgumentResolverUnitTests;
2-
31
/*
42
* Copyright 2017-2020 the original author or authors.
53
*
@@ -18,6 +16,6 @@
1816

1917
/**
2018
* @author Oliver Gierke
21-
* @see ProxyingHandlerMethodArgumentResolverUnitTests
19+
* @see org.springframework.data.web.ProxyingHandlerMethodArgumentResolverUnitTests
2220
*/
2321
public interface SampleInterface {}

src/test/java/org/springframework/data/DependencyTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import static de.schauderhaft.degraph.check.JCheck.*;
1919
import static org.junit.Assert.*;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
/**
2424
* @author Jens Schauder

src/test/java/org/springframework/data/annotation/TypeAliasUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
import java.util.Set;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323
import org.springframework.data.util.AnnotatedTypeScanner;
2424

2525
/**
2626
* Unit tests for {@link TypeAlias}.
2727
*
2828
* @author Oliver Gierke
2929
*/
30-
public class TypeAliasUnitTests {
30+
class TypeAliasUnitTests {
3131

3232
@Test // DATACMNS-547
3333
@SuppressWarnings("unchecked")
34-
public void scanningforAtPersistentFindsTypeAliasAnnotatedTypes() {
34+
void scanningforAtPersistentFindsTypeAliasAnnotatedTypes() {
3535

3636
AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(Persistent.class);
3737
Set<Class<?>> types = scanner.findTypes(getClass().getPackage().getName());

src/test/java/org/springframework/data/auditing/AnnotationAuditingMetadataUnitTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.lang.reflect.Field;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

2424
import org.springframework.data.annotation.CreatedDate;
2525
import org.springframework.util.ReflectionUtils;
@@ -31,15 +31,15 @@
3131
* @author Oliver Gierke
3232
* @since 1.5
3333
*/
34-
public class AnnotationAuditingMetadataUnitTests {
34+
class AnnotationAuditingMetadataUnitTests {
3535

3636
static final Field createdByField = ReflectionUtils.findField(AnnotatedUser.class, "createdBy");
3737
static final Field createdDateField = ReflectionUtils.findField(AnnotatedUser.class, "createdDate");
3838
static final Field lastModifiedByField = ReflectionUtils.findField(AnnotatedUser.class, "lastModifiedBy");
3939
static final Field lastModifiedDateField = ReflectionUtils.findField(AnnotatedUser.class, "lastModifiedDate");
4040

4141
@Test
42-
public void checkAnnotationDiscovery() {
42+
void checkAnnotationDiscovery() {
4343

4444
AnnotationAuditingMetadata metadata = AnnotationAuditingMetadata.getMetadata(AnnotatedUser.class);
4545

@@ -51,7 +51,7 @@ public void checkAnnotationDiscovery() {
5151
}
5252

5353
@Test
54-
public void checkCaching() {
54+
void checkCaching() {
5555

5656
AnnotationAuditingMetadata firstCall = AnnotationAuditingMetadata.getMetadata(AnnotatedUser.class);
5757
assertThat(firstCall).isNotNull();
@@ -61,7 +61,7 @@ public void checkCaching() {
6161
}
6262

6363
@Test
64-
public void checkIsAuditable() {
64+
void checkIsAuditable() {
6565

6666
AnnotationAuditingMetadata metadata = AnnotationAuditingMetadata.getMetadata(AnnotatedUser.class);
6767
assertThat(metadata).isNotNull();
@@ -73,7 +73,7 @@ public void checkIsAuditable() {
7373
}
7474

7575
@Test
76-
public void rejectsInvalidDateTypeField() {
76+
void rejectsInvalidDateTypeField() {
7777

7878
class Sample {
7979
@CreatedDate String field;

src/test/java/org/springframework/data/auditing/AuditingHandlerUnitTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import java.util.List;
2323
import java.util.Optional;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727
import org.springframework.data.annotation.CreatedBy;
2828
import org.springframework.data.annotation.CreatedDate;
2929
import org.springframework.data.annotation.LastModifiedBy;
@@ -39,15 +39,15 @@
3939
* @since 1.5
4040
*/
4141
@SuppressWarnings("unchecked")
42-
public class AuditingHandlerUnitTests {
42+
class AuditingHandlerUnitTests {
4343

4444
AuditingHandler handler;
4545
AuditorAware<AuditedUser> auditorAware;
4646

4747
AuditedUser user;
4848

49-
@Before
50-
public void setUp() {
49+
@BeforeEach
50+
void setUp() {
5151

5252
handler = getHandler();
5353
user = new AuditedUser();
@@ -64,7 +64,7 @@ protected AuditingHandler getHandler() {
6464
* Checks that the advice does not set auditor on the target entity if no {@code AuditorAware} was configured.
6565
*/
6666
@Test
67-
public void doesNotSetAuditorIfNotConfigured() {
67+
void doesNotSetAuditorIfNotConfigured() {
6868

6969
handler.markCreated(user);
7070

@@ -79,7 +79,7 @@ public void doesNotSetAuditorIfNotConfigured() {
7979
* Checks that the advice sets the auditor on the target entity if an {@code AuditorAware} was configured.
8080
*/
8181
@Test
82-
public void setsAuditorIfConfigured() {
82+
void setsAuditorIfConfigured() {
8383

8484
handler.setAuditorAware(auditorAware);
8585

@@ -98,7 +98,7 @@ public void setsAuditorIfConfigured() {
9898
* Checks that the advice does not set modification information on creation if the falg is set to {@code false}.
9999
*/
100100
@Test
101-
public void honoursModifiedOnCreationFlag() {
101+
void honoursModifiedOnCreationFlag() {
102102

103103
handler.setAuditorAware(auditorAware);
104104
handler.setModifyOnCreation(false);
@@ -117,7 +117,7 @@ public void honoursModifiedOnCreationFlag() {
117117
* Tests that the advice only sets modification data if a not-new entity is handled.
118118
*/
119119
@Test
120-
public void onlySetsModificationDataOnNotNewEntities() {
120+
void onlySetsModificationDataOnNotNewEntities() {
121121

122122
AuditedUser audited = new AuditedUser();
123123
audited.id = 1L;
@@ -135,7 +135,7 @@ public void onlySetsModificationDataOnNotNewEntities() {
135135
}
136136

137137
@Test
138-
public void doesNotSetTimeIfConfigured() {
138+
void doesNotSetTimeIfConfigured() {
139139

140140
handler.setDateTimeForNow(false);
141141
handler.setAuditorAware(auditorAware);
@@ -149,7 +149,7 @@ public void doesNotSetTimeIfConfigured() {
149149
}
150150

151151
@Test // DATAJPA-9
152-
public void usesDateTimeProviderIfConfigured() {
152+
void usesDateTimeProviderIfConfigured() {
153153

154154
DateTimeProvider provider = mock(DateTimeProvider.class);
155155
doReturn(Optional.empty()).when(provider).getNow();
@@ -161,7 +161,7 @@ public void usesDateTimeProviderIfConfigured() {
161161
}
162162

163163
@Test
164-
public void setsAuditingInfoOnEntityUsingInheritance() {
164+
void setsAuditingInfoOnEntityUsingInheritance() {
165165

166166
AuditingHandler handler = new AuditingHandler(PersistentEntities.of(new SampleMappingContext()));
167167
handler.setModifyOnCreation(false);

src/test/java/org/springframework/data/auditing/DefaultAuditableBeanWrapperFactoryUnitTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.time.temporal.TemporalAccessor;
2626
import java.util.Optional;
2727

28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import org.springframework.data.annotation.CreatedDate;
3131
import org.springframework.data.annotation.LastModifiedDate;
@@ -40,36 +40,36 @@
4040
* @author Jens Schauder
4141
* @since 1.5
4242
*/
43-
public class DefaultAuditableBeanWrapperFactoryUnitTests {
43+
class DefaultAuditableBeanWrapperFactoryUnitTests {
4444

4545
DefaultAuditableBeanWrapperFactory factory = new DefaultAuditableBeanWrapperFactory();
4646

4747
@Test
48-
public void rejectsNullSource() {
48+
void rejectsNullSource() {
4949
assertThatIllegalArgumentException().isThrownBy(() -> factory.getBeanWrapperFor(null));
5050
}
5151

5252
@Test
53-
public void returnsAuditableInterfaceBeanWrapperForAuditable() {
53+
void returnsAuditableInterfaceBeanWrapperForAuditable() {
5454

5555
assertThat(factory.getBeanWrapperFor(new AuditedUser()))
5656
.hasValueSatisfying(it -> assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class));
5757
}
5858

5959
@Test
60-
public void returnsReflectionAuditingBeanWrapperForNonAuditableButAnnotated() {
60+
void returnsReflectionAuditingBeanWrapperForNonAuditableButAnnotated() {
6161

6262
assertThat(factory.getBeanWrapperFor(new AnnotatedUser()))
6363
.hasValueSatisfying(it -> assertThat(it).isInstanceOf(ReflectionAuditingBeanWrapper.class));
6464
}
6565

6666
@Test
67-
public void returnsEmptyForNonAuditableType() {
67+
void returnsEmptyForNonAuditableType() {
6868
assertThat(factory.getBeanWrapperFor(new Object())).isNotPresent();
6969
}
7070

7171
@Test // DATACMNS-643
72-
public void setsJsr310AndThreeTenBpTypes() {
72+
void setsJsr310AndThreeTenBpTypes() {
7373

7474
Jsr310ThreeTenBpAuditedUser user = new Jsr310ThreeTenBpAuditedUser();
7575
Instant instant = Instant.now();
@@ -87,7 +87,7 @@ public void setsJsr310AndThreeTenBpTypes() {
8787
}
8888

8989
@Test // DATACMNS-867
90-
public void errorsWhenUnableToConvertDateViaIntermediateJavaUtilDateConversion() {
90+
void errorsWhenUnableToConvertDateViaIntermediateJavaUtilDateConversion() {
9191

9292
Jsr310ThreeTenBpAuditedUser user = new Jsr310ThreeTenBpAuditedUser();
9393
ZonedDateTime zonedDateTime = ZonedDateTime.now();
@@ -101,7 +101,7 @@ public void errorsWhenUnableToConvertDateViaIntermediateJavaUtilDateConversion()
101101
}
102102

103103
@Test // DATACMNS-1259
104-
public void lastModifiedDateAsLongIsAvailableViaWrapper() {
104+
void lastModifiedDateAsLongIsAvailableViaWrapper() {
105105

106106
LongBasedAuditable source = new LongBasedAuditable();
107107
source.dateModified = 42000L;
@@ -114,7 +114,7 @@ public void lastModifiedDateAsLongIsAvailableViaWrapper() {
114114
}
115115

116116
@Test // DATACMNS-1259
117-
public void canSetLastModifiedDateAsInstantViaWrapperOnLongField() {
117+
void canSetLastModifiedDateAsInstantViaWrapperOnLongField() {
118118

119119
LongBasedAuditable source = new LongBasedAuditable();
120120

@@ -127,7 +127,7 @@ public void canSetLastModifiedDateAsInstantViaWrapperOnLongField() {
127127
}
128128

129129
@Test // DATACMNS-1259
130-
public void canSetLastModifiedDateAsLocalDateTimeViaWrapperOnLongField() {
130+
void canSetLastModifiedDateAsLocalDateTimeViaWrapperOnLongField() {
131131

132132
LongBasedAuditable source = new LongBasedAuditable();
133133

@@ -140,7 +140,7 @@ public void canSetLastModifiedDateAsLocalDateTimeViaWrapperOnLongField() {
140140
}
141141

142142
@Test // DATACMNS-1259
143-
public void lastModifiedAsLocalDateTimeDateIsAvailableViaWrapperAsLocalDateTime() {
143+
void lastModifiedAsLocalDateTimeDateIsAvailableViaWrapperAsLocalDateTime() {
144144

145145
LocalDateTime now = LocalDateTime.now();
146146

src/test/java/org/springframework/data/auditing/IsNewAwareAuditingHandlerUnitTests.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
import java.util.Optional;
2121

22-
import org.junit.Before;
23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
25-
import org.mockito.junit.MockitoJUnitRunner;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.extension.ExtendWith;
25+
import org.mockito.junit.jupiter.MockitoExtension;
26+
import org.mockito.junit.jupiter.MockitoSettings;
27+
import org.mockito.quality.Strictness;
2628

2729
import org.springframework.data.annotation.Id;
2830
import org.springframework.data.mapping.context.PersistentEntities;
@@ -34,13 +36,14 @@
3436
* @author Oliver Gierke
3537
* @since 1.5
3638
*/
37-
@RunWith(MockitoJUnitRunner.class)
38-
public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests {
39+
@ExtendWith(MockitoExtension.class)
40+
@MockitoSettings(strictness = Strictness.LENIENT)
41+
class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests {
3942

4043
SampleMappingContext mappingContext;
4144

42-
@Before
43-
public void init() {
45+
@BeforeEach
46+
void init() {
4447

4548
this.mappingContext = new SampleMappingContext();
4649
this.mappingContext.getPersistentEntity(AuditedUser.class);
@@ -53,7 +56,7 @@ protected IsNewAwareAuditingHandler getHandler() {
5356
}
5457

5558
@Test
56-
public void delegatesToMarkCreatedForNewEntity() {
59+
void delegatesToMarkCreatedForNewEntity() {
5760

5861
AuditedUser user = new AuditedUser();
5962

@@ -64,7 +67,7 @@ public void delegatesToMarkCreatedForNewEntity() {
6467
}
6568

6669
@Test
67-
public void delegatesToMarkModifiedForNonNewEntity() {
70+
void delegatesToMarkModifiedForNonNewEntity() {
6871

6972
AuditedUser user = new AuditedUser();
7073
user.id = 1L;
@@ -76,17 +79,17 @@ public void delegatesToMarkModifiedForNonNewEntity() {
7679
}
7780

7881
@Test // DATACMNS-365
79-
public void rejectsNullMappingContext() {
82+
void rejectsNullMappingContext() {
8083
assertThatIllegalArgumentException().isThrownBy(() -> new IsNewAwareAuditingHandler((PersistentEntities) null));
8184
}
8285

8386
@Test // DATACMNS-365
84-
public void setsUpHandlerWithMappingContext() {
87+
void setsUpHandlerWithMappingContext() {
8588
new IsNewAwareAuditingHandler(PersistentEntities.of());
8689
}
8790

8891
@Test // DATACMNS-638
89-
public void handlingOptionalIsANoOp() {
92+
void handlingOptionalIsANoOp() {
9093

9194
IsNewAwareAuditingHandler handler = getHandler();
9295

@@ -96,7 +99,7 @@ public void handlingOptionalIsANoOp() {
9699
}
97100

98101
@Test // DATACMNS-957
99-
public void skipsEntityWithoutIdentifier() {
102+
void skipsEntityWithoutIdentifier() {
100103
getHandler().markAudited(Optional.of(new EntityWithoutId()));
101104
}
102105

src/test/java/org/springframework/data/auditing/Jsr310ThreeTenBpAuditedUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* @author Oliver Gierke
2525
*/
26-
public class Jsr310ThreeTenBpAuditedUser {
26+
class Jsr310ThreeTenBpAuditedUser {
2727

2828
@CreatedDate LocalDateTime createdDate;
2929
@LastModifiedDate org.threeten.bp.LocalDateTime lastModifiedDate;

0 commit comments

Comments
 (0)