Polishing Jackson encoder tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -95,12 +95,12 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||
new Pojo("foofoo", "barbar"),
|
||||
new Pojo("foofoofoo", "barbarbar"));
|
||||
|
||||
testEncodeAll(input, ResolvableType.forClass(Pojo.class), step -> step
|
||||
testEncodeAll(input, ResolvableType.forClass(Pojo.class), APPLICATION_STREAM_JSON, null, step -> step
|
||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n"))
|
||||
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n"))
|
||||
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n"))
|
||||
.verifyComplete(),
|
||||
APPLICATION_STREAM_JSON, null);
|
||||
.verifyComplete()
|
||||
);
|
||||
}
|
||||
|
||||
@Test // SPR-15866
|
||||
@@ -168,15 +168,15 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||
new Pojo("foofoofoo", "barbarbar")
|
||||
);
|
||||
|
||||
testEncode(input, ResolvableType.forClass(Pojo.class), step -> step
|
||||
testEncode(input, ResolvableType.forClass(Pojo.class), barMediaType, null, step -> step
|
||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n")
|
||||
.andThen(DataBufferUtils::release))
|
||||
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n")
|
||||
.andThen(DataBufferUtils::release))
|
||||
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n")
|
||||
.andThen(DataBufferUtils::release))
|
||||
.verifyComplete(),
|
||||
barMediaType, null);
|
||||
.verifyComplete()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,11 +190,10 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
|
||||
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView1.class);
|
||||
|
||||
testEncode(input, type, step -> step
|
||||
.consumeNextWith(expectString("{\"withView1\":\"with\"}")
|
||||
.andThen(DataBufferUtils::release))
|
||||
.verifyComplete(),
|
||||
null, hints);
|
||||
testEncode(input, type, null, hints, step -> step
|
||||
.consumeNextWith(expectString("{\"withView1\":\"with\"}").andThen(DataBufferUtils::release))
|
||||
.verifyComplete()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,11 +207,10 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
|
||||
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView3.class);
|
||||
|
||||
testEncode(input, type, step -> step
|
||||
.consumeNextWith(expectString("{\"withoutView\":\"without\"}")
|
||||
.andThen(DataBufferUtils::release))
|
||||
.verifyComplete(),
|
||||
null, hints);
|
||||
testEncode(input, type, null, hints, step -> step
|
||||
.consumeNextWith(expectString("{\"withoutView\":\"without\"}").andThen(DataBufferUtils::release))
|
||||
.verifyComplete()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,11 +225,10 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||
|
||||
ResolvableType type = ResolvableType.forClass(MappingJacksonValue.class);
|
||||
|
||||
testEncode(Mono.just(jacksonValue), type, step -> step
|
||||
.consumeNextWith(expectString("{\"withView1\":\"with\"}")
|
||||
.andThen(DataBufferUtils::release))
|
||||
.verifyComplete(),
|
||||
null, Collections.emptyMap());
|
||||
testEncode(Mono.just(jacksonValue), type, null, Collections.emptyMap(), step -> step
|
||||
.consumeNextWith(expectString("{\"withView1\":\"with\"}").andThen(DataBufferUtils::release))
|
||||
.verifyComplete()
|
||||
);
|
||||
}
|
||||
|
||||
@Test // gh-22771
|
||||
@@ -252,11 +249,12 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||
@Test
|
||||
public void encodeAscii() {
|
||||
Mono<Object> input = Mono.just(new Pojo("foo", "bar"));
|
||||
MimeType mimeType = new MimeType("application", "json", StandardCharsets.US_ASCII);
|
||||
|
||||
testEncode(input, ResolvableType.forClass(Pojo.class), step -> step
|
||||
testEncode(input, ResolvableType.forClass(Pojo.class), mimeType, null, step -> step
|
||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}"))
|
||||
.verifyComplete(),
|
||||
new MimeType("application", "json", StandardCharsets.US_ASCII), null);
|
||||
.verifyComplete()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -108,17 +108,13 @@ public class Jackson2SmileEncoderTests extends AbstractEncoderTests<Jackson2Smil
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeError() throws Exception {
|
||||
public void encodeError() {
|
||||
Mono<Pojo> input = Mono.error(new InputException());
|
||||
|
||||
testEncode(input, Pojo.class, step -> step
|
||||
.expectError(InputException.class)
|
||||
.verify());
|
||||
|
||||
testEncode(input, Pojo.class, step -> step.expectError(InputException.class).verify());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAsStream() throws Exception {
|
||||
public void encodeAsStream() {
|
||||
Pojo pojo1 = new Pojo("foo", "bar");
|
||||
Pojo pojo2 = new Pojo("foofoo", "barbar");
|
||||
Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -71,8 +71,8 @@ public class Jaxb2XmlEncoderTests extends AbstractEncoderTests<Jaxb2XmlEncoder>
|
||||
Mono<Pojo> input = Mono.just(new Pojo("foofoo", "barbar"));
|
||||
|
||||
testEncode(input, Pojo.class, step -> step
|
||||
.consumeNextWith(
|
||||
expectXml("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||
.consumeNextWith(expectXml(
|
||||
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||
"<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>"))
|
||||
.verifyComplete());
|
||||
}
|
||||
@@ -80,10 +80,7 @@ public class Jaxb2XmlEncoderTests extends AbstractEncoderTests<Jaxb2XmlEncoder>
|
||||
@Test
|
||||
public void encodeError() {
|
||||
Flux<Pojo> input = Flux.error(RuntimeException::new);
|
||||
|
||||
testEncode(input, Pojo.class, step -> step
|
||||
.expectError(RuntimeException.class)
|
||||
.verify());
|
||||
testEncode(input, Pojo.class, step -> step.expectError(RuntimeException.class).verify());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,9 +88,11 @@ public class Jaxb2XmlEncoderTests extends AbstractEncoderTests<Jaxb2XmlEncoder>
|
||||
Mono<Container> input = Mono.just(new Container());
|
||||
|
||||
testEncode(input, Pojo.class, step -> step
|
||||
.consumeNextWith(
|
||||
expectXml("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||
"<container><foo><name>name1</name></foo><bar><title>title1</title></bar></container>"))
|
||||
.consumeNextWith(expectXml(
|
||||
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||
"<container>" +
|
||||
"<foo><name>name1</name></foo><bar><title>title1</title></bar>" +
|
||||
"</container>"))
|
||||
.verifyComplete());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user