diff --git a/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/MapValidator.java b/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/MapValidator.java index dabe9a4..859ea8e 100644 --- a/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/MapValidator.java +++ b/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/MapValidator.java @@ -16,7 +16,7 @@ package xyz.zhouxy.plusone.validator; -import java.util.AbstractMap.SimpleEntry; +import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -205,7 +205,8 @@ public abstract class MapValidator extends BaseValidator> { protected final PairPropertyValidator, V1, V2> ruleForPair(K k1, K k2) { @SuppressWarnings("unchecked") - Function, Entry> getter = m -> new SimpleEntry((V1) m.get(k1), (V2) m.get(k2)); + Function, Entry> getter = m -> + new SimpleImmutableEntry<>((V1) m.get(k1), (V2) m.get(k2)); return ruleForPair(getter); } diff --git a/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/PairPropertyValidatorTests.java b/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/PairPropertyValidatorTests.java index 7b7ed03..29c61d1 100644 --- a/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/PairPropertyValidatorTests.java +++ b/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/PairPropertyValidatorTests.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Objects; -import java.util.AbstractMap.SimpleEntry; +import java.util.AbstractMap.SimpleImmutableEntry; import org.junit.jupiter.api.Test; @@ -43,7 +43,7 @@ public class PairPropertyValidatorTests { void must_validInput() { IValidator validator = new BaseValidator() { { - ruleForPair((ExampleCommand command) -> new SimpleEntry(command.getStringProperty(), command.getIntProperty())) + ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry(command.getStringProperty(), command.getIntProperty())) .must((str, intValue) -> Objects.equals(str, intValue.toString())) .must((str, intValue) -> Objects.equals(str, intValue.toString()), MESSAGE) .must((str, intValue) -> Objects.equals(str, intValue.toString()), () -> ExampleException.withMessage(MESSAGE)) @@ -60,7 +60,7 @@ public class PairPropertyValidatorTests { void must_default_invalidInput() { IValidator validator = new BaseValidator() { { - ruleForPair((ExampleCommand command) -> new SimpleEntry(command.getStringProperty(), command.getIntProperty())) + ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry(command.getStringProperty(), command.getIntProperty())) .must((str, intValue) -> Objects.equals(str, intValue.toString())); } }; @@ -75,7 +75,7 @@ public class PairPropertyValidatorTests { void must_message_invalidInput() { IValidator validator = new BaseValidator() { { - ruleForPair((ExampleCommand command) -> new SimpleEntry(command.getStringProperty(), command.getIntProperty())) + ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry(command.getStringProperty(), command.getIntProperty())) .must((str, intValue) -> Objects.equals(str, intValue.toString()), MESSAGE); } }; @@ -89,7 +89,7 @@ public class PairPropertyValidatorTests { void must_exceptionSupplier_invalidInput() { IValidator validator = new BaseValidator() { { - ruleForPair((ExampleCommand command) -> new SimpleEntry(command.getStringProperty(), command.getIntProperty())) + ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry(command.getStringProperty(), command.getIntProperty())) .must((str, intValue) -> Objects.equals(str, intValue.toString()), () -> ExampleException.withMessage(MESSAGE)); } }; @@ -104,7 +104,7 @@ public class PairPropertyValidatorTests { void must_exceptionFunction_invalidInput() { IValidator validator = new BaseValidator() { { - ruleForPair((ExampleCommand command) -> new SimpleEntry(command.getStringProperty(), command.getIntProperty())) + ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry(command.getStringProperty(), command.getIntProperty())) .must((str, intValue) -> Objects.equals(str, intValue.toString()), (str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue)); }