-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...st/java/org/hibernate/validator/testutil/PreconfiguredConstraintValidatorFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.validator.testutil; | ||
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.easymock.EasyMock.*; | ||
|
||
import java.util.Map; | ||
|
||
import jakarta.validation.ConstraintValidatorFactory; | ||
import jakarta.validation.ValidatorFactory; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
public class PreconfiguredConstraintValidatorFactoryTest { | ||
|
||
private ConstraintValidatorFactory delegatedConstraintValidatorFactory; | ||
private ValidatorFactory defaultValidationFactory; | ||
|
||
@BeforeMethod | ||
@SuppressWarnings("unchecked") | ||
public void setUp() { | ||
delegatedConstraintValidatorFactory = createMock( ConstraintValidatorFactory.class ); | ||
} | ||
|
||
@Test | ||
public void testGetInstanceWithPreconfiguredValidator() { | ||
CountValidationCallsValidator constraintValidator = new CountValidationCallsValidator(); | ||
|
||
PreconfiguredConstraintValidatorFactory constraintValidatorFactory = PreconfiguredConstraintValidatorFactory.builder() | ||
.delegated( delegatedConstraintValidatorFactory ) | ||
.defaultValidators( Map.of( CountValidationCallsValidator.class, constraintValidator ) ) | ||
.build(); | ||
|
||
assertThat( constraintValidatorFactory.getInstance( CountValidationCallsValidator.class ) ) | ||
.isEqualTo( constraintValidator ); | ||
} | ||
|
||
@Test | ||
public void testGetInstanceWithDefaultValidator() { | ||
CountValidationCallsValidator constraintValidator = new CountValidationCallsValidator(); | ||
|
||
expect( delegatedConstraintValidatorFactory.getInstance( CountValidationCallsValidator.class ) ).andReturn( constraintValidator ); | ||
|
||
PreconfiguredConstraintValidatorFactory constraintValidatorFactory = PreconfiguredConstraintValidatorFactory.builder() | ||
.delegated( delegatedConstraintValidatorFactory ) | ||
.build(); | ||
|
||
replay( delegatedConstraintValidatorFactory ); | ||
|
||
assertThat( constraintValidatorFactory.getInstance( CountValidationCallsValidator.class ) ) | ||
.isEqualTo( constraintValidator ); | ||
|
||
verify( delegatedConstraintValidatorFactory ); | ||
} | ||
|
||
@Test | ||
public void testReleaseInstance() { | ||
CountValidationCallsValidator constraintValidator = new CountValidationCallsValidator(); | ||
|
||
delegatedConstraintValidatorFactory.releaseInstance( constraintValidator ); | ||
|
||
PreconfiguredConstraintValidatorFactory constraintValidatorFactory = PreconfiguredConstraintValidatorFactory.builder() | ||
.delegated( delegatedConstraintValidatorFactory ) | ||
.build(); | ||
|
||
replay( delegatedConstraintValidatorFactory ); | ||
|
||
constraintValidatorFactory.releaseInstance( constraintValidator ); | ||
|
||
verify( delegatedConstraintValidatorFactory ); | ||
} | ||
} |