From f4d7bacf8f49026748df0c5a566d1c9ec00065ac Mon Sep 17 00:00:00 2001 From: Matt Benson Date: Tue, 26 Mar 2024 14:00:15 -0500 Subject: [PATCH] refactor --- .../validation/DefaultModelValidatorTest.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 8a7b4fe8b680..37d7546edc7d 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -20,6 +20,7 @@ import java.io.InputStream; import java.util.List; +import java.util.function.UnaryOperator; import junit.framework.TestCase; import org.apache.maven.model.Model; @@ -44,29 +45,41 @@ private Model read(String pom) throws Exception { } private SimpleProblemCollector validate(String pom) throws Exception { - return validateEffective(pom, ModelBuildingRequest.VALIDATION_LEVEL_STRICT); + return validateEffective(pom, UnaryOperator.identity()); } private SimpleProblemCollector validateRaw(String pom) throws Exception { - return validateRaw(pom, ModelBuildingRequest.VALIDATION_LEVEL_STRICT); + return validateRaw(pom, UnaryOperator.identity()); } private SimpleProblemCollector validateEffective(String pom, int level) throws Exception { - ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel(level); + return validateEffective(pom, mbr -> mbr.setValidationLevel(level)); + } + + private SimpleProblemCollector validateEffective(String pom, UnaryOperator requestConfigurer) + throws Exception { + Model model = read(pom); - SimpleProblemCollector problems = new SimpleProblemCollector(read(pom)); + SimpleProblemCollector problems = new SimpleProblemCollector(model); - validator.validateEffectiveModel(problems.getModel(), request, problems); + validator.validateEffectiveModel(model, requestConfigurer.apply(new DefaultModelBuildingRequest()), problems); return problems; } private SimpleProblemCollector validateRaw(String pom, int level) throws Exception { - ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel(level); + return validateRaw(pom, mbr -> mbr.setValidationLevel(level)); + } + + private SimpleProblemCollector validateRaw(String pom, UnaryOperator requestConfigurer) + throws Exception { + Model model = read(pom); + + SimpleProblemCollector problems = new SimpleProblemCollector(model); - SimpleProblemCollector problems = new SimpleProblemCollector(read(pom)); + ModelBuildingRequest request = requestConfigurer.apply(new DefaultModelBuildingRequest()); - validator.validateRawModel(problems.getModel(), request, problems); + validator.validateRawModel(model, request, problems); return problems; }