|
|
@ -16,11 +16,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.core.codec; |
|
|
|
package org.springframework.core.codec; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.Charset; |
|
|
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.ResolvableType; |
|
|
|
import org.springframework.core.ResolvableType; |
|
|
|
import org.springframework.util.MimeTypeUtils; |
|
|
|
import org.springframework.util.MimeTypeUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.ISO_8859_1; |
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.US_ASCII; |
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_16; |
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -65,4 +73,17 @@ public class CharSequenceEncoderTests |
|
|
|
.verifyComplete()); |
|
|
|
.verifyComplete()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void calculateCapacity() { |
|
|
|
|
|
|
|
String sequence = "Hello World!"; |
|
|
|
|
|
|
|
Stream.of(UTF_8, UTF_16, ISO_8859_1, US_ASCII, Charset.forName("BIG5")) |
|
|
|
|
|
|
|
.forEach(charset -> { |
|
|
|
|
|
|
|
int capacity = this.encoder.calculateCapacity(sequence, charset); |
|
|
|
|
|
|
|
int length = sequence.length(); |
|
|
|
|
|
|
|
assertTrue(String.format("%s has capacity %d; length %d", charset, capacity, length), |
|
|
|
|
|
|
|
capacity >= length); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|