Skip to content

Commit

Permalink
Fix resource leak
Browse files Browse the repository at this point in the history
  • Loading branch information
arey committed Dec 31, 2023
1 parent 0e6e000 commit aeca8ae
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
Expand All @@ -19,10 +21,17 @@
*/
class ValidatorTests {

private Validator createValidator() {
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
private LocalValidatorFactoryBean localValidatorFactoryBean;

@BeforeEach
void setUp() {
localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.afterPropertiesSet();
return localValidatorFactoryBean.getValidator();
}

@AfterEach
void tearDown() {
localValidatorFactoryBean.close();
}

@Test
Expand All @@ -42,4 +51,8 @@ void shouldNotValidateWhenFirstNameEmpty() {
assertThat(violation.getMessage()).isEqualTo("must not be empty");
}

private Validator createValidator() {
return localValidatorFactoryBean.getValidator();
}

}

0 comments on commit aeca8ae

Please sign in to comment.