Fix Class isAssignableFrom checks for Resource conversion

Issue: SPR-16606
This commit is contained in:
Rossen Stoyanchev
2018-03-16 16:17:02 -04:00
parent 842c29103f
commit 30583a62cf
3 changed files with 15 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
@@ -32,9 +31,8 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.StreamUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import static org.springframework.core.ResolvableType.*;
/**
* @author Arjen Poutsma
@@ -44,25 +42,22 @@ public class ResourceDecoderTests extends AbstractDataBufferAllocatingTestCase {
private final ResourceDecoder decoder = new ResourceDecoder();
@Test
public void canDecode() throws Exception {
assertTrue(this.decoder.canDecode(ResolvableType.forClass(InputStreamResource.class),
MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(ByteArrayResource.class),
MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(Resource.class),
MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(InputStreamResource.class),
MimeTypeUtils.APPLICATION_JSON));
public void canDecode() {
assertTrue(this.decoder.canDecode(forClass(InputStreamResource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(forClass(ByteArrayResource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(forClass(Resource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(forClass(InputStreamResource.class), MimeTypeUtils.APPLICATION_JSON));
assertFalse(this.decoder.canDecode(forClass(Object.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test
public void decode() throws Exception {
public void decode() {
DataBuffer fooBuffer = stringBuffer("foo");
DataBuffer barBuffer = stringBuffer("bar");
Flux<DataBuffer> source = Flux.just(fooBuffer, barBuffer);
Flux<Resource> result = this.decoder
.decode(source, ResolvableType.forClass(Resource.class), null, Collections.emptyMap());
.decode(source, forClass(Resource.class), null, Collections.emptyMap());
StepVerifier.create(result)
.consumeNextWith(resource -> {