Skip to content

Commit

Permalink
Adapt tests for Jackson ParameterNamesModule
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Aug 28, 2023
1 parent 2f43f77 commit ab699ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
Expand Down Expand Up @@ -229,9 +229,22 @@ public void decodeWithNullLiteral() {
StepVerifier.create(result).expectComplete().verify();
}

@Test
@Test // gh-27511
public void noDefaultConstructor() {
Flux<DataBuffer> input = Flux.from(stringBuffer("{\"property1\":\"foo\",\"property2\":\"bar\"}"));

testDecode(input, BeanWithNoDefaultConstructor.class, step -> step
.consumeNextWith(o -> {
assertThat(o.getProperty1()).isEqualTo("foo");
assertThat(o.getProperty2()).isEqualTo("bar");
})
.verifyComplete()
);
}

@Test
public void codecException() {
Flux<DataBuffer> input = Flux.from(stringBuffer("["));
ResolvableType elementType = ResolvableType.forClass(BeanWithNoDefaultConstructor.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(input, elementType, null, Collections.emptyMap());
StepVerifier.create(flux).verifyError(CodecException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ public void writeSubTypeList() throws Exception {
assertThat(result).contains("\"number\":123");
}

@Test
@Test // gh-27511
public void readWithNoDefaultConstructor() throws Exception {
String body = "{\"property1\":\"foo\",\"property2\":\"bar\"}";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(MediaType.APPLICATION_JSON);
assertThatExceptionOfType(HttpMessageConversionException.class).isThrownBy(() ->
converter.read(BeanWithNoDefaultConstructor.class, inputMessage))
.withMessageStartingWith("Type definition error:");
BeanWithNoDefaultConstructor bean = (BeanWithNoDefaultConstructor) converter.read(BeanWithNoDefaultConstructor.class, inputMessage);
assertThat(bean.property1).isEqualTo("foo");
assertThat(bean.property2).isEqualTo("bar");
}

@Test
Expand Down

0 comments on commit ab699ee

Please sign in to comment.