From 20da9826ccad6c98daf70039a10820ba0bf1d8ee Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 28 Apr 2021 13:54:19 +0200 Subject: [PATCH] Disable incrementalBuildTypeRenamed test This commit disables a test that does not test what it is supposed to and improve the Metadata assertions to fail early if more than one matching item by name and type is found in the metadata. See gh-26271 --- ...ncrementalBuildMetadataGenerationTests.java | 4 +++- .../metadata/Metadata.java | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java index 4fe9d67833..a026356c13 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -16,6 +16,7 @@ package org.springframework.boot.configurationprocessor; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; @@ -74,6 +75,7 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration } @Test + @Disabled("gh-26271") void incrementalBuildTypeRenamed() throws Exception { TestProject project = new TestProject(this.tempDir, FooProperties.class, BarProperties.class); ConfigurationMetadata metadata = project.fullBuild(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java index 69e3d914cf..05c52deb66 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 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. @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.assertj.core.api.Condition; import org.hamcrest.collection.IsMapContaining; @@ -131,7 +132,7 @@ public final class Metadata { @Override public boolean matches(ConfigurationMetadata value) { - ItemMetadata itemMetadata = getFirstItemWithName(value, this.name); + ItemMetadata itemMetadata = findItem(value, this.name); if (itemMetadata == null) { return false; } @@ -207,13 +208,14 @@ public final class Metadata { this.description, this.defaultValue, null); } - private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata, String name) { - for (ItemMetadata item : metadata.getItems()) { - if (item.isOfItemType(this.itemType) && name.equals(item.getName())) { - return item; - } + private ItemMetadata findItem(ConfigurationMetadata metadata, String name) { + List candidates = metadata.getItems().stream() + .filter((item) -> item.isOfItemType(this.itemType) && name.equals(item.getName())) + .collect(Collectors.toList()); + if (candidates.size() > 1) { + throw new IllegalStateException("More that one metadata item with name '" + name + "': " + candidates); } - return null; + return (candidates.size() == 1) ? candidates.get(0) : null; } }