Browse Source

Polishing

(cherry picked from commit 95a56cd28d)
pull/1952/head
Juergen Hoeller 8 years ago
parent
commit
8ce9236b0f
  1. 8
      spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java
  2. 14
      spring-context/src/test/java/org/springframework/validation/beanvalidation/SpringValidatorAdapterTests.java
  3. 27
      spring-context/src/test/java/org/springframework/validation/beanvalidation/ValidatorFactoryTests.java
  4. 5
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java
  5. 30
      spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java

8
spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -23,7 +23,7 @@ import org.springframework.util.ObjectUtils; @@ -23,7 +23,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* Default implementation of the {@link MessageSourceResolvable} interface.
* Spring's default implementation of the {@link MessageSourceResolvable} interface.
* Offers an easy way to store all the necessary values needed to resolve
* a message via a {@link org.springframework.context.MessageSource}.
*
@ -133,8 +133,8 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable, @@ -133,8 +133,8 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable,
}
/**
* Default implementation exposes the attributes of this MessageSourceResolvable.
* To be overridden in more specific subclasses, potentially including the
* The default implementation exposes the attributes of this MessageSourceResolvable.
* <p>To be overridden in more specific subclasses, potentially including the
* resolvable content through {@code resolvableToString()}.
* @see #resolvableToString()
*/

14
spring-context/src/test/java/org/springframework/validation/beanvalidation/SpringValidatorAdapterTests.java

@ -70,7 +70,7 @@ public class SpringValidatorAdapterTests { @@ -70,7 +70,7 @@ public class SpringValidatorAdapterTests {
@Before
public void setupSpringValidatorAdapter() {
messageSource.addMessage("Size", Locale.ENGLISH, "Size of {0} is must be between {2} and {1}");
messageSource.addMessage("Same", Locale.ENGLISH, "{2} must be same value with {1}");
messageSource.addMessage("Same", Locale.ENGLISH, "{2} must be same value as {1}");
messageSource.addMessage("password", Locale.ENGLISH, "Password");
messageSource.addMessage("confirmPassword", Locale.ENGLISH, "Password(Confirm)");
}
@ -107,7 +107,7 @@ public class SpringValidatorAdapterTests { @@ -107,7 +107,7 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("password"), is(1));
assertThat(messageSource.getMessage(errors.getFieldError("password"), Locale.ENGLISH),
is("Password must be same value with Password(Confirm)"));
is("Password must be same value as Password(Confirm)"));
}
@Test // SPR-13406
@ -122,7 +122,7 @@ public class SpringValidatorAdapterTests { @@ -122,7 +122,7 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("email"), is(1));
assertThat(errors.getFieldErrorCount("confirmEmail"), is(1));
assertThat(messageSource.getMessage(errors.getFieldError("email"), Locale.ENGLISH),
is("email must be same value with confirmEmail"));
is("email must be same value as confirmEmail"));
assertThat(messageSource.getMessage(errors.getFieldError("confirmEmail"), Locale.ENGLISH),
is("Email required"));
}
@ -141,7 +141,7 @@ public class SpringValidatorAdapterTests { @@ -141,7 +141,7 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("email"), is(1));
assertThat(errors.getFieldErrorCount("confirmEmail"), is(1));
assertThat(messageSource.getMessage(errors.getFieldError("email"), Locale.ENGLISH),
is("email must be same value with confirmEmail"));
is("email must be same value as confirmEmail"));
assertThat(messageSource.getMessage(errors.getFieldError("confirmEmail"), Locale.ENGLISH),
is("Email required"));
}
@ -354,13 +354,13 @@ public class SpringValidatorAdapterTests { @@ -354,13 +354,13 @@ public class SpringValidatorAdapterTests {
private Integer id;
@javax.validation.constraints.NotNull
@NotNull
private String name;
@javax.validation.constraints.NotNull
@NotNull
private Integer age;
@javax.validation.constraints.NotNull
@NotNull
private Parent parent;
public Integer getId() {

27
spring-context/src/test/java/org/springframework/validation/beanvalidation/ValidatorFactoryTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -54,14 +54,12 @@ import static org.hamcrest.Matchers.*; @@ -54,14 +54,12 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Tests against Hibernate Validator 5.x.
*
* @author Juergen Hoeller
*/
public class ValidatorFactoryTests {
@Test
public void testSimpleValidation() throws Exception {
public void testSimpleValidation() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -114,9 +112,10 @@ public class ValidatorFactoryTests { @@ -114,9 +112,10 @@ public class ValidatorFactoryTests {
}
@Test
public void testSimpleValidationWithClassLevel() throws Exception {
public void testSimpleValidationWithClassLevel() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
ValidPerson person = new ValidPerson();
person.setName("Juergen");
person.getAddress().setStreet("Juergen's Street");
@ -129,7 +128,7 @@ public class ValidatorFactoryTests { @@ -129,7 +128,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testSpringValidationFieldType() throws Exception {
public void testSpringValidationFieldType() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -144,7 +143,7 @@ public class ValidatorFactoryTests { @@ -144,7 +143,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testSpringValidation() throws Exception {
public void testSpringValidation() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -172,7 +171,7 @@ public class ValidatorFactoryTests { @@ -172,7 +171,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testSpringValidationWithClassLevel() throws Exception {
public void testSpringValidationWithClassLevel() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -190,7 +189,7 @@ public class ValidatorFactoryTests { @@ -190,7 +189,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testSpringValidationWithAutowiredValidator() throws Exception {
public void testSpringValidationWithAutowiredValidator() {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
LocalValidatorFactoryBean.class);
LocalValidatorFactoryBean validator = ctx.getBean(LocalValidatorFactoryBean.class);
@ -211,7 +210,7 @@ public class ValidatorFactoryTests { @@ -211,7 +210,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testSpringValidationWithErrorInListElement() throws Exception {
public void testSpringValidationWithErrorInListElement() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -229,7 +228,7 @@ public class ValidatorFactoryTests { @@ -229,7 +228,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testSpringValidationWithErrorInSetElement() throws Exception {
public void testSpringValidationWithErrorInSetElement() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -247,7 +246,7 @@ public class ValidatorFactoryTests { @@ -247,7 +246,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testInnerBeanValidation() throws Exception {
public void testInnerBeanValidation() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -259,7 +258,7 @@ public class ValidatorFactoryTests { @@ -259,7 +258,7 @@ public class ValidatorFactoryTests {
}
@Test
public void testValidationWithOptionalField() throws Exception {
public void testValidationWithOptionalField() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
@ -412,7 +411,7 @@ public class ValidatorFactoryTests { @@ -412,7 +411,7 @@ public class ValidatorFactoryTests {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Constraint(validatedBy=InnerValidator.class)
public static @interface InnerValid {
public @interface InnerValid {
String message() default "NOT VALID";

5
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -43,8 +43,7 @@ public class OpEQ extends Operator { @@ -43,8 +43,7 @@ public class OpEQ extends Operator {
Object right = getRightOperand().getValueInternal(state).getValue();
this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left);
this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right);
return BooleanTypedValue.forValue(
equalityCheck(state.getEvaluationContext(), left, right));
return BooleanTypedValue.forValue(equalityCheck(state.getEvaluationContext(), left, right));
}
// This check is different to the one in the other numeric operators (OpLt/etc)

30
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -252,12 +252,12 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { @@ -252,12 +252,12 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
private String password;
private Boolean readOnly = Boolean.FALSE;
private Integer transactionIsolation;
private Boolean autoCommit;
private boolean readOnly = false;
private boolean closed = false;
private Connection target;
@ -311,11 +311,15 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { @@ -311,11 +311,15 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
if (method.getName().equals("toString")) {
return "Lazy Connection proxy for target DataSource [" + getTargetDataSource() + "]";
}
else if (method.getName().equals("isReadOnly")) {
return this.readOnly;
else if (method.getName().equals("getAutoCommit")) {
if (this.autoCommit != null) {
return this.autoCommit;
}
// Else fetch actual Connection and check there,
// because we didn't have a default specified.
}
else if (method.getName().equals("setReadOnly")) {
this.readOnly = (Boolean) args[0];
else if (method.getName().equals("setAutoCommit")) {
this.autoCommit = (Boolean) args[0];
return null;
}
else if (method.getName().equals("getTransactionIsolation")) {
@ -329,15 +333,11 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { @@ -329,15 +333,11 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
this.transactionIsolation = (Integer) args[0];
return null;
}
else if (method.getName().equals("getAutoCommit")) {
if (this.autoCommit != null) {
return this.autoCommit;
}
// Else fetch actual Connection and check there,
// because we didn't have a default specified.
else if (method.getName().equals("isReadOnly")) {
return this.readOnly;
}
else if (method.getName().equals("setAutoCommit")) {
this.autoCommit = (Boolean) args[0];
else if (method.getName().equals("setReadOnly")) {
this.readOnly = (Boolean) args[0];
return null;
}
else if (method.getName().equals("commit")) {

Loading…
Cancel
Save