Skip to content

Commit 660006b

Browse files
committed
DATACMNS-1554 - Migrate tests to AssertJ.
1 parent 31975b5 commit 660006b

11 files changed

+81
-186
lines changed

src/test/java/org/springframework/data/convert/CustomConversionsUnitTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package org.springframework.data.convert;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.hamcrest.Matchers.*;
20-
import static org.junit.Assert.assertThat;
18+
import static org.assertj.core.api.Assertions.*;
2119

2220
import java.text.DateFormat;
2321
import java.text.Format;
@@ -29,6 +27,7 @@
2927

3028
import org.joda.time.DateTime;
3129
import org.junit.Test;
30+
3231
import org.springframework.aop.framework.ProxyFactory;
3332
import org.springframework.core.convert.converter.Converter;
3433
import org.springframework.core.convert.converter.ConverterFactory;
@@ -38,6 +37,7 @@
3837
import org.springframework.data.convert.ConverterBuilder.ConverterAware;
3938
import org.springframework.data.convert.CustomConversions.StoreConversions;
4039
import org.springframework.data.mapping.model.SimpleTypeHolder;
40+
4141
import org.threeten.bp.LocalDateTime;
4242

4343
/**
@@ -93,24 +93,24 @@ public void populatesConversionServiceCorrectly() {
9393
Arrays.asList(StringToFormatConverter.INSTANCE));
9494
conversions.registerConvertersIn(conversionService);
9595

96-
assertThat(conversionService.canConvert(String.class, Format.class), is(true));
96+
assertThat(conversionService.canConvert(String.class, Format.class)).isTrue();
9797
}
9898

9999
@Test // DATAMONGO-259, DATACMNS-1035
100100
public void doesNotConsiderTypeSimpleIfOnlyReadConverterIsRegistered() {
101101

102102
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
103103
Arrays.asList(StringToFormatConverter.INSTANCE));
104-
assertThat(conversions.isSimpleType(Format.class), is(false));
104+
assertThat(conversions.isSimpleType(Format.class)).isFalse();
105105
}
106106

107107
@Test // DATAMONGO-298, DATACMNS-1035
108108
public void discoversConvertersForSubtypesOfMongoTypes() {
109109

110110
CustomConversions conversions = new CustomConversions(StoreConversions.NONE,
111111
Arrays.asList(StringToIntegerConverter.INSTANCE));
112-
assertThat(conversions.hasCustomReadTarget(String.class, Integer.class), is(true));
113-
assertThat(conversions.hasCustomWriteTarget(String.class, Integer.class), is(true));
112+
assertThat(conversions.hasCustomReadTarget(String.class, Integer.class)).isTrue();
113+
assertThat(conversions.hasCustomWriteTarget(String.class, Integer.class)).isTrue();
114114
}
115115

116116
@Test // DATAMONGO-795, DATACMNS-1035

src/test/java/org/springframework/data/domain/ExampleMatcherUnitTests.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.domain;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.hamcrest.Matchers.*;
2019
import static org.springframework.data.domain.ExampleMatcher.*;
2120

2221
import org.junit.Before;
@@ -34,77 +33,77 @@ public class ExampleMatcherUnitTests {
3433
ExampleMatcher matcher;
3534

3635
@Before
37-
public void setUp() throws Exception {
36+
public void setUp() {
3837
matcher = matching();
3938
}
4039

4140
@Test // DATACMNS-810
42-
public void defaultStringMatcherShouldReturnDefault() throws Exception {
41+
public void defaultStringMatcherShouldReturnDefault() {
4342
assertThat(matcher.getDefaultStringMatcher()).isEqualTo(StringMatcher.DEFAULT);
4443
}
4544

4645
@Test // DATACMNS-810
47-
public void ignoreCaseShouldReturnFalseByDefault() throws Exception {
46+
public void ignoreCaseShouldReturnFalseByDefault() {
4847
assertThat(matcher.isIgnoreCaseEnabled()).isFalse();
4948
}
5049

5150
@Test // DATACMNS-810
52-
public void ignoredPathsIsEmptyByDefault() throws Exception {
51+
public void ignoredPathsIsEmptyByDefault() {
5352
assertThat(matcher.getIgnoredPaths()).isEmpty();
5453
}
5554

5655
@Test // DATACMNS-810
57-
public void nullHandlerShouldReturnIgnoreByDefault() throws Exception {
56+
public void nullHandlerShouldReturnIgnoreByDefault() {
5857
assertThat(matcher.getNullHandler()).isEqualTo(NullHandler.IGNORE);
5958
}
6059

6160
@Test(expected = UnsupportedOperationException.class) // DATACMNS-810
62-
public void ignoredPathsIsNotModifiable() throws Exception {
61+
public void ignoredPathsIsNotModifiable() {
6362
matcher.getIgnoredPaths().add(\\_(ツ)_/¯");
6463
}
6564

6665
@Test // DATACMNS-810
67-
public void ignoreCaseShouldReturnTrueWhenIgnoreCaseEnabled() throws Exception {
66+
public void ignoreCaseShouldReturnTrueWhenIgnoreCaseEnabled() {
6867

6968
matcher = matching().withIgnoreCase();
7069

7170
assertThat(matcher.isIgnoreCaseEnabled()).isTrue();
7271
}
7372

7473
@Test // DATACMNS-810
75-
public void ignoreCaseShouldReturnTrueWhenIgnoreCaseSet() throws Exception {
74+
public void ignoreCaseShouldReturnTrueWhenIgnoreCaseSet() {
7675

7776
matcher = matching().withIgnoreCase(true);
7877

7978
assertThat(matcher.isIgnoreCaseEnabled()).isTrue();
8079
}
8180

8281
@Test // DATACMNS-810
83-
public void nullHandlerShouldReturnInclude() throws Exception {
82+
public void nullHandlerShouldReturnInclude() {
8483

8584
matcher = matching().withIncludeNullValues();
8685

8786
assertThat(matcher.getNullHandler()).isEqualTo(NullHandler.INCLUDE);
8887
}
8988

9089
@Test // DATACMNS-810
91-
public void nullHandlerShouldReturnIgnore() throws Exception {
90+
public void nullHandlerShouldReturnIgnore() {
9291

9392
matcher = matching().withIgnoreNullValues();
9493

9594
assertThat(matcher.getNullHandler()).isEqualTo(NullHandler.IGNORE);
9695
}
9796

9897
@Test // DATACMNS-810
99-
public void nullHandlerShouldReturnConfiguredValue() throws Exception {
98+
public void nullHandlerShouldReturnConfiguredValue() {
10099

101100
matcher = matching().withNullHandler(NullHandler.INCLUDE);
102101

103102
assertThat(matcher.getNullHandler()).isEqualTo(NullHandler.INCLUDE);
104103
}
105104

106105
@Test // DATACMNS-810
107-
public void ignoredPathsShouldReturnCorrectProperties() throws Exception {
106+
public void ignoredPathsShouldReturnCorrectProperties() {
108107

109108
matcher = matching().withIgnorePaths("foo", "bar", "baz");
110109

@@ -113,7 +112,7 @@ public void ignoredPathsShouldReturnCorrectProperties() throws Exception {
113112
}
114113

115114
@Test // DATACMNS-810
116-
public void ignoredPathsShouldReturnUniqueProperties() throws Exception {
115+
public void ignoredPathsShouldReturnUniqueProperties() {
117116

118117
matcher = matching().withIgnorePaths("foo", "bar", "foo");
119118

@@ -122,12 +121,12 @@ public void ignoredPathsShouldReturnUniqueProperties() throws Exception {
122121
}
123122

124123
@Test // DATACMNS-810
125-
public void withCreatesNewInstance() throws Exception {
124+
public void withCreatesNewInstance() {
126125

127126
matcher = matching().withIgnorePaths("foo", "bar", "foo");
128127
ExampleMatcher configuredExampleSpec = matcher.withIgnoreCase();
129128

130-
assertThat(matcher).isNotEqualTo(sameInstance(configuredExampleSpec));
129+
assertThat(matcher).isNotSameAs(configuredExampleSpec);
131130
assertThat(matcher.getIgnoredPaths()).hasSize(2);
132131
assertThat(matcher.isIgnoreCaseEnabled()).isFalse();
133132

@@ -157,31 +156,29 @@ public void anyMatcherYieldsAnyMatching() {
157156
}
158157

159158
@Test // DATACMNS-900
160-
public void shouldCompareUsingHashCodeAndEquals() throws Exception {
159+
public void shouldCompareUsingHashCodeAndEquals() {
161160

162161
matcher = matching() //
163162
.withIgnorePaths("foo", "bar", "baz") //
164163
.withNullHandler(NullHandler.IGNORE) //
165164
.withIgnoreCase("ignored-case") //
166165
.withMatcher("hello", GenericPropertyMatchers.contains().caseSensitive()) //
167-
.withMatcher("world", matcher -> matcher.endsWith());
166+
.withMatcher("world", GenericPropertyMatcher::endsWith);
168167

169168
ExampleMatcher sameAsMatcher = matching() //
170169
.withIgnorePaths("foo", "bar", "baz") //
171170
.withNullHandler(NullHandler.IGNORE) //
172171
.withIgnoreCase("ignored-case") //
173172
.withMatcher("hello", GenericPropertyMatchers.contains().caseSensitive()) //
174-
.withMatcher("world", matcher -> matcher.endsWith());
173+
.withMatcher("world", GenericPropertyMatcher::endsWith);
175174

176175
ExampleMatcher different = matching() //
177176
.withIgnorePaths("foo", "bar", "baz") //
178177
.withNullHandler(NullHandler.IGNORE) //
179178
.withMatcher("hello", GenericPropertyMatchers.contains().ignoreCase());
180179

181-
assertThat(matcher.hashCode()).isEqualTo(sameAsMatcher.hashCode());
182-
assertThat(matcher.hashCode()).isNotEqualTo(different.hashCode());
183-
assertThat(matcher).isEqualTo(sameAsMatcher);
184-
assertThat(matcher).isNotEqualTo(different);
180+
assertThat(matcher.hashCode()).isEqualTo(sameAsMatcher.hashCode()).isNotEqualTo(different.hashCode());
181+
assertThat(matcher).isEqualTo(sameAsMatcher).isNotEqualTo(different);
185182
}
186183

187184
static class Person {

src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.mapping.model;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.junit.Assume.*;
2019
import static org.mockito.Mockito.*;
2120

2221
import lombok.RequiredArgsConstructor;
@@ -31,14 +30,14 @@
3130
import java.util.concurrent.atomic.AtomicBoolean;
3231
import java.util.stream.Stream;
3332

34-
import org.hamcrest.CoreMatchers;
3533
import org.junit.Rule;
3634
import org.junit.Test;
3735
import org.junit.rules.ExpectedException;
3836
import org.junit.runner.RunWith;
3937
import org.mockito.Mock;
4038
import org.mockito.Mockito;
4139
import org.mockito.junit.MockitoJUnitRunner;
40+
4241
import org.springframework.core.annotation.AliasFor;
4342
import org.springframework.data.annotation.AccessType;
4443
import org.springframework.data.annotation.AccessType.Type;
@@ -192,21 +191,6 @@ public void reportsRequiredPropertyName() {
192191
.hasMessageContaining("Required property foo not found");
193192
}
194193

195-
@Test // DATACMNS-596
196-
public void returnsBeanWrapperForPropertyAccessor() {
197-
198-
assumeThat(System.getProperty("java.version"), CoreMatchers.startsWith("1.6"));
199-
200-
SampleMappingContext context = new SampleMappingContext();
201-
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
202-
203-
Entity value = new Entity();
204-
PersistentPropertyAccessor<Entity> accessor = entity.getPropertyAccessor(value);
205-
206-
assertThat(accessor).isInstanceOf(BeanWrapper.class);
207-
assertThat(accessor.getBean()).isEqualTo(value);
208-
}
209-
210194
@Test // DATACMNS-809
211195
public void returnsGeneratedPropertyAccessorForPropertyAccessor() {
212196

src/test/java/org/springframework/data/repository/config/RepositoryComponentProviderUnitTests.java

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import java.util.List;
2323
import java.util.Set;
2424

25-
import org.hamcrest.BaseMatcher;
26-
import org.hamcrest.Description;
2725
import org.junit.Test;
26+
2827
import org.springframework.beans.factory.config.BeanDefinition;
2928
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3029
import org.springframework.core.type.filter.AssignableTypeFilter;
@@ -92,40 +91,5 @@ public void exposesBeanDefinitionRegistry() {
9291
assertThat(provider.getRegistry()).isEqualTo(registry);
9392
}
9493

95-
static class BeanDefinitionOfTypeMatcher extends BaseMatcher<BeanDefinition> {
96-
97-
private final Class<?> expectedType;
98-
99-
private BeanDefinitionOfTypeMatcher(Class<?> expectedType) {
100-
this.expectedType = expectedType;
101-
}
102-
103-
public static BeanDefinitionOfTypeMatcher beanDefinitionOfType(Class<?> expectedType) {
104-
return new BeanDefinitionOfTypeMatcher(expectedType);
105-
}
106-
107-
/*
108-
* (non-Javadoc)
109-
* @see org.hamcrest.Matcher#matches(java.lang.Object)
110-
*/
111-
@Override
112-
public boolean matches(Object item) {
113-
114-
if (!(item instanceof BeanDefinition)) {
115-
return false;
116-
}
117-
118-
BeanDefinition definition = (BeanDefinition) item;
119-
return definition.getBeanClassName().equals(expectedType.getName());
120-
}
121-
122-
/*
123-
* (non-Javadoc)
124-
* @see org.hamcrest.SelfDescribing#describeTo(org.hamcrest.Description)
125-
*/
126-
@Override
127-
public void describeTo(Description description) {}
128-
}
129-
13094
public interface MyNestedRepository extends Repository<Person, Long> {}
13195
}

src/test/java/org/springframework/data/repository/config/RepositoryConfigurationDelegateUnitTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
*/
1616
package org.springframework.data.repository.config;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.hamcrest.CoreMatchers.*;
20-
import static org.junit.Assert.assertThat;
18+
import static org.assertj.core.api.Assertions.*;
2119

2220
import org.junit.Test;
2321
import org.junit.runner.RunWith;
2422
import org.mockito.Mock;
2523
import org.mockito.junit.MockitoJUnitRunner;
24+
2625
import org.springframework.aop.TargetSource;
2726
import org.springframework.aop.framework.Advised;
2827
import org.springframework.beans.factory.ListableBeanFactory;
@@ -67,8 +66,8 @@ public void registersRepositoryBeanNameAsAttribute() {
6766

6867
BeanDefinition beanDefinition = definition.getBeanDefinition();
6968

70-
assertThat(beanDefinition.getAttribute(RepositoryConfigurationDelegate.FACTORY_BEAN_OBJECT_TYPE).toString(),
71-
endsWith("Repository"));
69+
assertThat(beanDefinition.getAttribute(RepositoryConfigurationDelegate.FACTORY_BEAN_OBJECT_TYPE).toString())
70+
.endsWith("Repository");
7271
}
7372
}
7473

src/test/java/org/springframework/data/repository/config/ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.repository.config;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.hamcrest.Matchers.*;
2019

2120
import java.util.List;
2221

@@ -83,7 +82,7 @@ private static void assertIsListOfClasspathResourcesWithPath(Object source, Stri
8382

8483
assertThat(source).isInstanceOf(List.class);
8584
List<?> list = (List<?>) source;
86-
assertThat(list).isNotEqualTo(empty());
85+
assertThat(list).isNotEmpty();
8786
Object element = list.get(0);
8887
assertThat(element).isInstanceOf(ClassPathResource.class);
8988
ClassPathResource resource = (ClassPathResource) element;

0 commit comments

Comments
 (0)