Polishing

This commit is contained in:
Juergen Hoeller 2024-01-31 17:12:20 +01:00
parent 9b2b485444
commit 00577ed80a
7 changed files with 36 additions and 40 deletions

View File

@ -81,8 +81,8 @@ class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(gb); BeanWrapper bw = new BeanWrapperImpl(gb);
Set<TestBean> input = new HashSet<>(); Set<TestBean> input = new HashSet<>();
input.add(new TestBean()); input.add(new TestBean());
assertThatExceptionOfType(TypeMismatchException.class).isThrownBy(() -> assertThatExceptionOfType(TypeMismatchException.class)
bw.setPropertyValue("integerSet", input)) .isThrownBy(() -> bw.setPropertyValue("integerSet", input))
.withMessageContaining("java.lang.Integer"); .withMessageContaining("java.lang.Integer");
} }

View File

@ -103,8 +103,8 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
pvs.addPropertyValue(new PropertyValue("age", "foobar")); pvs.addPropertyValue(new PropertyValue("age", "foobar"));
pvs.addPropertyValue(new PropertyValue("name", newName)); pvs.addPropertyValue(new PropertyValue("name", newName));
pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy)); pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy));
assertThatExceptionOfType(PropertyBatchUpdateException.class).isThrownBy(() -> assertThatExceptionOfType(PropertyBatchUpdateException.class)
accessor.setPropertyValues(pvs)) .isThrownBy(() -> accessor.setPropertyValues(pvs))
.satisfies(ex -> { .satisfies(ex -> {
assertThat(ex.getExceptionCount()).isEqualTo(2); assertThat(ex.getExceptionCount()).isEqualTo(2);
assertThat(ex.getPropertyAccessException("touchy").getPropertyChangeEvent() assertThat(ex.getPropertyAccessException("touchy").getPropertyChangeEvent()
@ -119,8 +119,8 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
void checkNotWritablePropertyHoldPossibleMatches() { void checkNotWritablePropertyHoldPossibleMatches() {
TestBean target = new TestBean(); TestBean target = new TestBean();
BeanWrapper accessor = createAccessor(target); BeanWrapper accessor = createAccessor(target);
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() -> assertThatExceptionOfType(NotWritablePropertyException.class)
accessor.setPropertyValue("ag", "foobar")) .isThrownBy(() -> accessor.setPropertyValue("ag", "foobar"))
.satisfies(ex -> assertThat(ex.getPossibleMatches()).containsExactly("age")); .satisfies(ex -> assertThat(ex.getPossibleMatches()).containsExactly("age"));
} }
@ -294,8 +294,8 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
void incompletelyQuotedKeyLeadsToPropertyException() { void incompletelyQuotedKeyLeadsToPropertyException() {
TestBean target = new TestBean(); TestBean target = new TestBean();
BeanWrapper accessor = createAccessor(target); BeanWrapper accessor = createAccessor(target);
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() -> assertThatExceptionOfType(NotWritablePropertyException.class)
accessor.setPropertyValue("[']", "foobar")) .isThrownBy(() -> accessor.setPropertyValue("[']", "foobar"))
.satisfies(ex -> assertThat(ex.getPossibleMatches()).isNull()); .satisfies(ex -> assertThat(ex.getPossibleMatches()).isNull());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -152,8 +152,7 @@ public interface Resource extends InputStreamSource {
} }
/** /**
* Returns the contents of this resource as a string, using the specified * Return the contents of this resource as a string, using the specified charset.
* charset.
* @param charset the charset to use for decoding * @param charset the charset to use for decoding
* @return the contents of this resource as a {@code String} * @return the contents of this resource as a {@code String}
* @throws java.io.FileNotFoundException if the resource cannot be resolved as * @throws java.io.FileNotFoundException if the resource cannot be resolved as

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,8 +45,8 @@ import org.springframework.util.Assert;
* lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength); * lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength);
* lobCreator.setClobAsString(ps, 3, description); * lobCreator.setClobAsString(ps, 3, description);
* } * }
* } * });
* );</pre> * </pre>
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.0.2 * @since 1.0.2

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,8 +46,8 @@ import org.springframework.lang.Nullable;
* public void streamData(ResultSet rs) throws SQLException, IOException { * public void streamData(ResultSet rs) throws SQLException, IOException {
* FileCopyUtils.copy(lobHandler.getBlobAsBinaryStream(rs, 1), contentStream); * FileCopyUtils.copy(lobHandler.getBlobAsBinaryStream(rs, 1), contentStream);
* } * }
* } * });
* );</pre> * </pre>
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.0.2 * @since 1.0.2

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,9 +20,7 @@ import org.springframework.jdbc.support.SqlValue;
/** /**
* Subinterface of {@link org.springframework.jdbc.support.SqlValue} * Subinterface of {@link org.springframework.jdbc.support.SqlValue}
* that supports passing in XML data to specified column and adds a * that specifically indicates passing in XML data to a specified column.
* cleanup callback, to be invoked after the value has been set and
* the corresponding statement has been executed.
* *
* @author Thomas Risberg * @author Thomas Risberg
* @since 2.5.5 * @since 2.5.5

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -95,8 +95,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
long length = inputMessage.getHeaders().getContentLength(); long length = inputMessage.getHeaders().getContentLength();
byte[] bytes = (length >= 0 && length <= Integer.MAX_VALUE ? byte[] bytes = (length >= 0 && length <= Integer.MAX_VALUE ?
inputMessage.getBody().readNBytes((int) length) : inputMessage.getBody().readNBytes((int) length) : inputMessage.getBody().readAllBytes());
inputMessage.getBody().readAllBytes());
return new String(bytes, charset); return new String(bytes, charset);
} }
@ -110,10 +109,9 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
@Override @Override
protected void addDefaultHeaders(HttpHeaders headers, String s, @Nullable MediaType type) throws IOException { protected void addDefaultHeaders(HttpHeaders headers, String s, @Nullable MediaType type) throws IOException {
if (headers.getContentType() == null ) { if (headers.getContentType() == null ) {
if (type != null && type.isConcrete() && if (type != null && type.isConcrete() && (type.isCompatibleWith(MediaType.APPLICATION_JSON) ||
(type.isCompatibleWith(MediaType.APPLICATION_JSON) ||
type.isCompatibleWith(APPLICATION_PLUS_JSON))) { type.isCompatibleWith(APPLICATION_PLUS_JSON))) {
// Prevent charset parameter for JSON.. // Prevent charset parameter for JSON.
headers.setContentType(type); headers.setContentType(type);
} }
} }
@ -167,4 +165,5 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
protected boolean supportsRepeatableWrites(String s) { protected boolean supportsRepeatableWrites(String s) {
return true; return true;
} }
} }