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 2eda053..e724bf2 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 @@ -83,6 +83,12 @@ public abstract class MapValidator extends BaseValidator> { return ruleForString(m -> (String) m.get(key)); } + protected final > ComparablePropertyValidator, E> ruleForComparable(K key) { + @SuppressWarnings("unchecked") + Function, E> getter = m -> (E) m.get(key); + return ruleForComparable(getter); + } + protected final CollectionPropertyValidator, E> ruleForCollection(K key) { @SuppressWarnings("unchecked") Function, Collection> getter = m -> (Collection) m.get(key); diff --git a/plusone-validator/src/test/java/xyz/zhouxy/plusone/map/validator/MapValidatorTests.java b/plusone-validator/src/test/java/xyz/zhouxy/plusone/map/validator/MapValidatorTests.java index 3cc7327..b2a2afe 100644 --- a/plusone-validator/src/test/java/xyz/zhouxy/plusone/map/validator/MapValidatorTests.java +++ b/plusone-validator/src/test/java/xyz/zhouxy/plusone/map/validator/MapValidatorTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024-2025 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package xyz.zhouxy.plusone.map.validator; import static org.junit.jupiter.api.Assertions.*; @@ -102,7 +118,7 @@ class ParamsValidator extends MapValidator { .notNull(d -> ExampleException.withMessage("The doubleProperty cannot be null, but it was %s", d)); ruleForString(STRING_PROPERTY) .notNull(); - ruleFor(DATE_TIME_PROPERTY) + ruleForComparable(DATE_TIME_PROPERTY) .notNull("The dateTimeProperty cannot be null"); ruleFor(OBJECT_PROPERTY) .notNull(() -> ExampleException.withMessage("The objectProperty cannot be null"));