Browse Source

Polishing

pull/32172/head
Juergen Hoeller 2 years ago
parent
commit
00577ed80a
  1. 6
      spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java
  2. 26
      spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java
  3. 5
      spring-core/src/main/java/org/springframework/core/io/Resource.java
  4. 6
      spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobCreatingPreparedStatementCallback.java
  5. 16
      spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java
  6. 6
      spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlValue.java
  7. 11
      spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java

6
spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java

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

26
spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java

@ -103,13 +103,13 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests { @@ -103,13 +103,13 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
pvs.addPropertyValue(new PropertyValue("age", "foobar"));
pvs.addPropertyValue(new PropertyValue("name", newName));
pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy));
assertThatExceptionOfType(PropertyBatchUpdateException.class).isThrownBy(() ->
accessor.setPropertyValues(pvs))
.satisfies(ex -> {
assertThat(ex.getExceptionCount()).isEqualTo(2);
assertThat(ex.getPropertyAccessException("touchy").getPropertyChangeEvent()
.getNewValue()).isEqualTo(invalidTouchy);
});
assertThatExceptionOfType(PropertyBatchUpdateException.class)
.isThrownBy(() -> accessor.setPropertyValues(pvs))
.satisfies(ex -> {
assertThat(ex.getExceptionCount()).isEqualTo(2);
assertThat(ex.getPropertyAccessException("touchy").getPropertyChangeEvent()
.getNewValue()).isEqualTo(invalidTouchy);
});
// Test validly set property matches
assertThat(target.getName()).as("Valid set property must stick").isEqualTo(newName);
assertThat(target.getAge()).as("Invalid set property must retain old value").isEqualTo(0);
@ -119,9 +119,9 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests { @@ -119,9 +119,9 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
void checkNotWritablePropertyHoldPossibleMatches() {
TestBean target = new TestBean();
BeanWrapper accessor = createAccessor(target);
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
accessor.setPropertyValue("ag", "foobar"))
.satisfies(ex -> assertThat(ex.getPossibleMatches()).containsExactly("age"));
assertThatExceptionOfType(NotWritablePropertyException.class)
.isThrownBy(() -> accessor.setPropertyValue("ag", "foobar"))
.satisfies(ex -> assertThat(ex.getPossibleMatches()).containsExactly("age"));
}
@Test // Can't be shared; there is no such thing as a read-only field
@ -294,9 +294,9 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests { @@ -294,9 +294,9 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
void incompletelyQuotedKeyLeadsToPropertyException() {
TestBean target = new TestBean();
BeanWrapper accessor = createAccessor(target);
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
accessor.setPropertyValue("[']", "foobar"))
.satisfies(ex -> assertThat(ex.getPossibleMatches()).isNull());
assertThatExceptionOfType(NotWritablePropertyException.class)
.isThrownBy(() -> accessor.setPropertyValue("[']", "foobar"))
.satisfies(ex -> assertThat(ex.getPossibleMatches()).isNull());
}

5
spring-core/src/main/java/org/springframework/core/io/Resource.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -152,8 +152,7 @@ public interface Resource extends InputStreamSource { @@ -152,8 +152,7 @@ public interface Resource extends InputStreamSource {
}
/**
* Returns the contents of this resource as a string, using the specified
* charset.
* Return the contents of this resource as a string, using the specified charset.
* @param charset the charset to use for decoding
* @return the contents of this resource as a {@code String}
* @throws java.io.FileNotFoundException if the resource cannot be resolved as

6
spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobCreatingPreparedStatementCallback.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -45,8 +45,8 @@ import org.springframework.util.Assert; @@ -45,8 +45,8 @@ import org.springframework.util.Assert;
* lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength);
* lobCreator.setClobAsString(ps, 3, description);
* }
* }
* );</pre>
* });
* </pre>
*
* @author Juergen Hoeller
* @since 1.0.2

16
spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -41,13 +41,13 @@ import org.springframework.lang.Nullable; @@ -41,13 +41,13 @@ import org.springframework.lang.Nullable;
* final LobHandler lobHandler = new DefaultLobHandler(); // reusable object
*
* jdbcTemplate.query(
* "SELECT content FROM imagedb WHERE image_name=?", new Object[] {name},
* new AbstractLobStreamingResultSetExtractor() {
* public void streamData(ResultSet rs) throws SQLException, IOException {
* FileCopyUtils.copy(lobHandler.getBlobAsBinaryStream(rs, 1), contentStream);
* }
* }
* );</pre>
* "SELECT content FROM imagedb WHERE image_name=?", new Object[] {name},
* new AbstractLobStreamingResultSetExtractor() {
* public void streamData(ResultSet rs) throws SQLException, IOException {
* FileCopyUtils.copy(lobHandler.getBlobAsBinaryStream(rs, 1), contentStream);
* }
* });
* </pre>
*
* @author Juergen Hoeller
* @since 1.0.2

6
spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlValue.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -20,9 +20,7 @@ import org.springframework.jdbc.support.SqlValue; @@ -20,9 +20,7 @@ import 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
* cleanup callback, to be invoked after the value has been set and
* the corresponding statement has been executed.
* that specifically indicates passing in XML data to a specified column.
*
* @author Thomas Risberg
* @since 2.5.5

11
spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java

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

Loading…
Cancel
Save