* let @BeanListFactoryBean@ regards bean order before handing them out to clients
git-svn-id: svn+ssh://svn.synyx.de/var/svn/synyx/opensource/hera/trunk@6963 5a64d73e-33d6-4ccc-9058-23f8668ecac9
This commit is contained in:
@@ -46,6 +46,12 @@
|
|||||||
<version>1.2.15</version>
|
<version>1.2.15</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.easymock</groupId>
|
||||||
|
<artifactId>easymock</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class BeanListFactoryBean<T> extends AbstractTypeAwareSupport<T>
|
|||||||
List<T> beans = getBeans();
|
List<T> beans = getBeans();
|
||||||
Collections.sort(beans, COMPARATOR);
|
Collections.sort(beans, COMPARATOR);
|
||||||
|
|
||||||
return getBeans();
|
return beans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package org.synyx.hera.core.support;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for {@link BeanListFactoryBean}.
|
||||||
|
*
|
||||||
|
* @author Oliver Gierke - gierke@synyx.de
|
||||||
|
*/
|
||||||
|
public class BeanListFactoryBeanUnitTest {
|
||||||
|
|
||||||
|
private BeanListFactoryBean<Ordered> factory;
|
||||||
|
private ApplicationContext context;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
|
||||||
|
context = createNiceMock(ApplicationContext.class);
|
||||||
|
|
||||||
|
factory = new BeanListFactoryBean<Ordered>();
|
||||||
|
factory.setApplicationContext(context);
|
||||||
|
factory.setType(Ordered.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void regardsOrderOfBeans() throws Exception {
|
||||||
|
|
||||||
|
// They shall be switched in the result.
|
||||||
|
Ordered first = getOrdered(5);
|
||||||
|
Ordered second = getOrdered(0);
|
||||||
|
|
||||||
|
Map<String, Ordered> beans = new HashMap<String, Ordered>();
|
||||||
|
beans.put("first", first);
|
||||||
|
beans.put("second", second);
|
||||||
|
|
||||||
|
expect(context.getBeansOfType(Ordered.class)).andReturn(beans)
|
||||||
|
.anyTimes();
|
||||||
|
replay(context);
|
||||||
|
|
||||||
|
Object result = factory.getObject();
|
||||||
|
assertTrue(result instanceof List<?>);
|
||||||
|
|
||||||
|
List<Ordered> members = (List) result;
|
||||||
|
|
||||||
|
assertEquals(0, members.indexOf(second));
|
||||||
|
assertEquals(1, members.indexOf(first));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an {@link Ordered} with the given order.
|
||||||
|
*
|
||||||
|
* @param order
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Ordered getOrdered(final int order) {
|
||||||
|
|
||||||
|
return new Ordered() {
|
||||||
|
|
||||||
|
public int getOrder() {
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user