Skip to content

Commit

Permalink
Fix validator creation
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Feb 11, 2024
1 parent 8a34dfb commit 26b0610
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -36,8 +38,21 @@ public final class PropertiesContainValidatorTest {

private PropertiesContain constraintAnnotation;

private static ValidatorFactory validatorFactory;

private Validator validator;

@BeforeAll
public static void beforeAll() {
validatorFactory = Validation.buildDefaultValidatorFactory();
}

@AfterAll
public static void afterAll() {
validatorFactory.close();
validatorFactory = null;
}

@BeforeEach
public final void setUp() {
testee = new PropertiesContainValidator();
Expand All @@ -46,9 +61,7 @@ public final void setUp() {
expect(constraintAnnotation.value()).andReturn(expected);
replay(constraintAnnotation);
testee.initialize(constraintAnnotation);
try (final ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
validator = factory.getValidator();
}
validator = validatorFactory.getValidator();
}

@AfterEach
Expand Down

0 comments on commit 26b0610

Please sign in to comment.