#1379 - Test cases to show that what's described is generally working.
This commit is contained in:
@@ -383,7 +383,6 @@ public class RepresentationModelProcessorInvoker {
|
||||
* @param target that target {@link ResolvableType}.
|
||||
* @return
|
||||
*/
|
||||
|
||||
static boolean isValueTypeMatch(@Nullable CollectionModel<?> collectionModel, ResolvableType target) {
|
||||
|
||||
if (collectionModel == null) {
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.hateoas.server.mvc;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
|
||||
@@ -35,12 +35,25 @@ public class RepresentationModelProcessorInvokerUnitTests {
|
||||
void doesNotInvokeGenericProcessorForCollectionModel() {
|
||||
|
||||
RepresentationModelProcessorInvoker invoker = new RepresentationModelProcessorInvoker(
|
||||
Collections.singletonList(new GenericPostProcessor<>()));
|
||||
singletonList(new GenericPostProcessor<>()));
|
||||
|
||||
assertThatCode(() -> invoker.invokeProcessorsFor(CollectionModel.empty())) //
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test // #1379
|
||||
void doesNotInvokeProcessorForNonAssignableNestedEntity() {
|
||||
|
||||
FirstEntityProcessor processor = new FirstEntityProcessor();
|
||||
RepresentationModelProcessorInvoker invoker = new RepresentationModelProcessorInvoker(
|
||||
singletonList(processor));
|
||||
|
||||
EntityModel<SecondEntity> entityModel = EntityModel.of(new SecondEntity());
|
||||
invoker.invokeProcessorsFor(CollectionModel.of(singleton(entityModel)));
|
||||
|
||||
assertThat(processor.invoked).isFalse();
|
||||
}
|
||||
|
||||
// #1280
|
||||
|
||||
static class GenericPostProcessor<T extends GenericModel<T>> implements RepresentationModelProcessor<T> {
|
||||
@@ -52,4 +65,21 @@ public class RepresentationModelProcessorInvokerUnitTests {
|
||||
}
|
||||
|
||||
static class GenericModel<T extends RepresentationModel<T>> extends RepresentationModel<T> {}
|
||||
|
||||
static class FirstEntity {}
|
||||
|
||||
static class SecondEntity {};
|
||||
|
||||
static class FirstEntityProcessor implements RepresentationModelProcessor<CollectionModel<EntityModel<FirstEntity>>> {
|
||||
|
||||
boolean invoked = false;
|
||||
|
||||
@Override
|
||||
public CollectionModel<EntityModel<FirstEntity>> process(CollectionModel<EntityModel<FirstEntity>> model) {
|
||||
|
||||
invoked = true;
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user