DATAREST-1410 - Migrate remaining tests to AssertJ.
This commit is contained in:
@@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.core.domain.Person;
|
||||
import org.springframework.data.rest.core.domain.PersonRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Base class for integration tests loading {@link RepositoryTestsConfig} and populating the {@link PersonRepository}
|
||||
@@ -29,7 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = RepositoryTestsConfig.class)
|
||||
public abstract class AbstractIntegrationTests {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.rest.core.context;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -29,19 +30,9 @@ import org.springframework.data.rest.core.domain.EventHandlerInvokedException;
|
||||
import org.springframework.data.rest.core.domain.Person;
|
||||
import org.springframework.data.rest.core.domain.PersonBeforeSaveHandler;
|
||||
import org.springframework.data.rest.core.domain.PersonRepository;
|
||||
import org.springframework.data.rest.core.event.AfterCreateEvent;
|
||||
import org.springframework.data.rest.core.event.AfterDeleteEvent;
|
||||
import org.springframework.data.rest.core.event.AfterLinkDeleteEvent;
|
||||
import org.springframework.data.rest.core.event.AfterLinkSaveEvent;
|
||||
import org.springframework.data.rest.core.event.AfterSaveEvent;
|
||||
import org.springframework.data.rest.core.event.AnnotatedEventHandlerInvoker;
|
||||
import org.springframework.data.rest.core.event.BeforeCreateEvent;
|
||||
import org.springframework.data.rest.core.event.BeforeDeleteEvent;
|
||||
import org.springframework.data.rest.core.event.BeforeLinkDeleteEvent;
|
||||
import org.springframework.data.rest.core.event.BeforeLinkSaveEvent;
|
||||
import org.springframework.data.rest.core.event.BeforeSaveEvent;
|
||||
import org.springframework.data.rest.core.event.*;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Tests around the {@link org.springframework.context.ApplicationEvent} handling abstractions.
|
||||
@@ -49,7 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class RepositoryEventIntegrationTests {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.data.rest.core.domain.PersonNameValidator;
|
||||
import org.springframework.data.rest.core.event.BeforeSaveEvent;
|
||||
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Tests to check the {@link org.springframework.validation.Validator} integration.
|
||||
@@ -41,7 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ValidatorIntegrationTests {
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.data.rest.core.domain.Person;
|
||||
import org.springframework.data.rest.core.domain.Profile;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RepositoryResourceMappings}.
|
||||
@@ -52,7 +52,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
public class RepositoryResourceMappingsIntegrationTests {
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -23,14 +23,12 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.domain.Profile;
|
||||
@@ -52,8 +50,6 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
PersistentEntities entities;
|
||||
List<EntityLookup<?>> lookups;
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -95,7 +91,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
Profile profile = new Profile("Name", "Type");
|
||||
Link link = provider.createSelfLinkFor(profile);
|
||||
|
||||
assertThat(link.getHref(), Matchers.endsWith(profile.getId().toString()));
|
||||
assertThat(link.getHref()).endsWith(profile.getId().toString());
|
||||
}
|
||||
|
||||
@Test // DATAREST-724
|
||||
@@ -106,20 +102,18 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
when(lookup.supports(Profile.class)).thenReturn(true);
|
||||
when(lookup.getResourceIdentifier(any(Profile.class))).thenReturn("foo");
|
||||
|
||||
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, Arrays.asList(lookup));
|
||||
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, Collections.singletonList(lookup));
|
||||
|
||||
Link link = provider.createSelfLinkFor(new Profile("Name", "Type"));
|
||||
|
||||
assertThat(link.getHref(), Matchers.endsWith("foo"));
|
||||
assertThat(link.getHref()).endsWith("foo");
|
||||
}
|
||||
|
||||
@Test // DATAREST-724
|
||||
public void rejectsLinkCreationForUnknownEntity() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(Object.class.getName());
|
||||
exception.expectMessage("Couldn't find PersistentEntity for");
|
||||
|
||||
provider.createSelfLinkFor(new Object());
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> provider.createSelfLinkFor(new Object())) //
|
||||
.withMessageContaining(Object.class.getName()) //
|
||||
.withMessageContaining("Couldn't find PersistentEntity for");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user