Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
(cherry picked from commit 95a56cd)
  • Loading branch information
jhoeller committed Aug 31, 2018
1 parent 1a626ab commit 8ce9236
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,7 +23,7 @@
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}.
*
Expand Down Expand Up @@ -133,8 +133,8 @@ protected final String resolvableToString() {
}

/**
* 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()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public void testApplyMessageSourceResolvableToStringArgumentValueWithResolvedLog

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
Expand All @@ -122,7 +122,7 @@ public void testApplyMessageSourceResolvableToStringArgumentValueWithUnresolvedL
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"));
}
Expand All @@ -141,7 +141,7 @@ public void testApplyMessageSourceResolvableToStringArgumentValueWithAlwaysUseMe
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"));
}
Expand Down Expand Up @@ -354,13 +354,13 @@ public static class Child {

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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -54,14 +54,12 @@
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();

Expand Down Expand Up @@ -114,9 +112,10 @@ public void testSimpleValidationWithCustomProvider() throws Exception {
}

@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");
Expand All @@ -129,7 +128,7 @@ public void testSimpleValidationWithClassLevel() throws Exception {
}

@Test
public void testSpringValidationFieldType() throws Exception {
public void testSpringValidationFieldType() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand All @@ -144,7 +143,7 @@ public void testSpringValidationFieldType() throws Exception {
}

@Test
public void testSpringValidation() throws Exception {
public void testSpringValidation() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand Down Expand Up @@ -172,7 +171,7 @@ public void testSpringValidation() throws Exception {
}

@Test
public void testSpringValidationWithClassLevel() throws Exception {
public void testSpringValidationWithClassLevel() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand All @@ -190,7 +189,7 @@ public void testSpringValidationWithClassLevel() throws Exception {
}

@Test
public void testSpringValidationWithAutowiredValidator() throws Exception {
public void testSpringValidationWithAutowiredValidator() {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
LocalValidatorFactoryBean.class);
LocalValidatorFactoryBean validator = ctx.getBean(LocalValidatorFactoryBean.class);
Expand All @@ -211,7 +210,7 @@ public void testSpringValidationWithAutowiredValidator() throws Exception {
}

@Test
public void testSpringValidationWithErrorInListElement() throws Exception {
public void testSpringValidationWithErrorInListElement() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand All @@ -229,7 +228,7 @@ public void testSpringValidationWithErrorInListElement() throws Exception {
}

@Test
public void testSpringValidationWithErrorInSetElement() throws Exception {
public void testSpringValidationWithErrorInSetElement() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand All @@ -247,7 +246,7 @@ public void testSpringValidationWithErrorInSetElement() throws Exception {
}

@Test
public void testInnerBeanValidation() throws Exception {
public void testInnerBeanValidation() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand All @@ -259,7 +258,7 @@ public void testInnerBeanValidation() throws Exception {
}

@Test
public void testValidationWithOptionalField() throws Exception {
public void testValidationWithOptionalField() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

Expand Down Expand Up @@ -412,7 +411,7 @@ public void setValue(String value) {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Constraint(validatedBy=InnerValidator.class)
public static @interface InnerValid {
public @interface InnerValid {

String message() default "NOT VALID";

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -43,8 +43,7 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -252,12 +252,12 @@ private class LazyConnectionInvocationHandler implements InvocationHandler {

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;
Expand Down Expand Up @@ -311,11 +311,15 @@ else if (method.getName().equals("getTargetConnection")) {
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")) {
Expand All @@ -329,15 +333,11 @@ else if (method.getName().equals("setTransactionIsolation")) {
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")) {
Expand Down

0 comments on commit 8ce9236

Please sign in to comment.