From 5c6105d20846dffa6e957fc9792c19a62d535daa Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 13 Feb 2025 12:42:54 +0100 Subject: [PATCH] GH-107 - Remove support for injecting lists of beans. --- .../core/support/BeanListFactoryBean.java | 67 --------------- .../support/BeanListFactoryBeanUnitTest.java | 83 ------------------- 2 files changed, 150 deletions(-) delete mode 100644 core/src/main/java/org/springframework/plugin/core/support/BeanListFactoryBean.java delete mode 100644 core/src/test/java/org/springframework/plugin/core/support/BeanListFactoryBeanUnitTest.java diff --git a/core/src/main/java/org/springframework/plugin/core/support/BeanListFactoryBean.java b/core/src/main/java/org/springframework/plugin/core/support/BeanListFactoryBean.java deleted file mode 100644 index 37d15a9..0000000 --- a/core/src/main/java/org/springframework/plugin/core/support/BeanListFactoryBean.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008-2010 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 org.springframework.plugin.core.support; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.springframework.beans.factory.FactoryBean; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.NonNull; - -/** - * Factory to create bean lists for a given type. Exposes all beans of the configured type that can be found in the - * {@link org.springframework.context.ApplicationContext}. - * - * @author Oliver Gierke - */ -public class BeanListFactoryBean extends AbstractTypeAwareSupport implements FactoryBean> { - - private static final Comparator COMPARATOR = new AnnotationAwareOrderComparator(); - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.FactoryBean#getObject() - */ - @NonNull - public List getObject() { - - List beans = new ArrayList(); - beans.addAll(getBeans()); - Collections.sort(beans, COMPARATOR); - - return beans; - } - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.FactoryBean#getObjectType() - */ - @NonNull - public Class getObjectType() { - return List.class; - } - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.FactoryBean#isSingleton() - */ - public boolean isSingleton() { - return true; - } -} diff --git a/core/src/test/java/org/springframework/plugin/core/support/BeanListFactoryBeanUnitTest.java b/core/src/test/java/org/springframework/plugin/core/support/BeanListFactoryBeanUnitTest.java deleted file mode 100644 index 578aa22..0000000 --- a/core/src/test/java/org/springframework/plugin/core/support/BeanListFactoryBeanUnitTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2008-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. - * 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 org.springframework.plugin.core.support; - -import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.ApplicationContext; -import org.springframework.core.Ordered; - -/** - * Unit test for {@link BeanListFactoryBean}. - * - * @author Oliver Gierke - */ -@ExtendWith(MockitoExtension.class) -class BeanListFactoryBeanUnitTest { - - BeanListFactoryBean factory; - - @Mock ApplicationContext context; - - @BeforeEach - void setUp() { - - factory = new BeanListFactoryBean(); - factory.setApplicationContext(context); - factory.setType(Ordered.class); - factory.afterPropertiesSet(); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - void regardsOrderOfBeans() throws Exception { - - // They shall be switched in the result. - Ordered first = () -> 5; - Ordered second = () -> 0; - - when(context.getBeanNamesForType(Ordered.class, false, false)).thenReturn(new String[] { "first", "second" }); - when(context.getType(any(String.class))).thenReturn((Class) Ordered.class); - when(context.getBean("first")).thenReturn(first); - when(context.getBean("second")).thenReturn(second); - - Object result = factory.getObject(); - assertThat(result).isInstanceOfSatisfying(List.class, it -> { - - assertThat(it.indexOf(second)).isEqualByComparingTo(0); - assertThat(it.indexOf(first)).isEqualTo(1); - }); - } - - @Test - @SuppressWarnings("unchecked") - public void returnsEmptyListIfNoBeansFound() throws Exception { - - when(context.getBeanNamesForType(Ordered.class, false, false)).thenReturn(new String[0]); - - Object result = factory.getObject(); - assertThat(result).isInstanceOfSatisfying(List.class, it -> assertThat(it).isEmpty()); - } -}