1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -1515,12 +1515,16 @@ void orderFromAttribute() {
1515
1515
bd1 .setAttribute (AbstractBeanDefinition .ORDER_ATTRIBUTE , Ordered .LOWEST_PRECEDENCE );
1516
1516
lbf .registerBeanDefinition ("bean1" , bd1 );
1517
1517
GenericBeanDefinition bd2 = new GenericBeanDefinition ();
1518
- bd2 .setBeanClass (TestBean .class );
1518
+ bd2 .setBeanClass (DerivedTestBean .class );
1519
1519
bd2 .setPropertyValues (new MutablePropertyValues (List .of (new PropertyValue ("name" , "highest" ))));
1520
1520
bd2 .setAttribute (AbstractBeanDefinition .ORDER_ATTRIBUTE , Ordered .HIGHEST_PRECEDENCE );
1521
1521
lbf .registerBeanDefinition ("bean2" , bd2 );
1522
1522
assertThat (lbf .getBeanProvider (TestBean .class ).orderedStream ().map (TestBean ::getName ))
1523
1523
.containsExactly ("highest" , "lowest" );
1524
+ assertThat (lbf .getBeanProvider (TestBean .class ).orderedStream (ObjectProvider .UNFILTERED ).map (TestBean ::getName ))
1525
+ .containsExactly ("highest" , "lowest" );
1526
+ assertThat (lbf .getBeanProvider (TestBean .class ).orderedStream (clazz -> !DerivedTestBean .class .isAssignableFrom (clazz ))
1527
+ .map (TestBean ::getName )).containsExactly ("lowest" );
1524
1528
}
1525
1529
1526
1530
@ Test
@@ -1540,6 +1544,8 @@ void orderFromAttributeOverrideAnnotation() {
1540
1544
lbf .registerBeanDefinition ("bean2" , bd2 );
1541
1545
assertThat (lbf .getBeanProvider (TestBean .class ).orderedStream ().map (TestBean ::getName ))
1542
1546
.containsExactly ("fromLowestPrecedenceTestBeanFactoryBean" , "fromHighestPrecedenceTestBeanFactoryBean" );
1547
+ assertThat (lbf .getBeanProvider (TestBean .class ).orderedStream (ObjectProvider .UNFILTERED ).map (TestBean ::getName ))
1548
+ .containsExactly ("fromLowestPrecedenceTestBeanFactoryBean" , "fromHighestPrecedenceTestBeanFactoryBean" );
1543
1549
}
1544
1550
1545
1551
@ Test
@@ -1934,6 +1940,11 @@ void getBeanByTypeInstanceWithAmbiguity() {
1934
1940
assertThat (resolved ).hasSize (2 );
1935
1941
assertThat (resolved ).contains (lbf .getBean ("bd1" ));
1936
1942
assertThat (resolved ).contains (lbf .getBean ("bd2" ));
1943
+
1944
+ resolved = provider .stream (ObjectProvider .UNFILTERED ).collect (Collectors .toSet ());
1945
+ assertThat (resolved ).hasSize (2 );
1946
+ assertThat (resolved ).contains (lbf .getBean ("bd1" ));
1947
+ assertThat (resolved ).contains (lbf .getBean ("bd2" ));
1937
1948
}
1938
1949
1939
1950
@ Test
@@ -1983,6 +1994,11 @@ void getBeanByTypeInstanceWithPrimary() {
1983
1994
assertThat (resolved ).hasSize (2 );
1984
1995
assertThat (resolved ).contains (lbf .getBean ("bd1" ));
1985
1996
assertThat (resolved ).contains (lbf .getBean ("bd2" ));
1997
+
1998
+ resolved = provider .stream (ObjectProvider .UNFILTERED ).collect (Collectors .toSet ());
1999
+ assertThat (resolved ).hasSize (2 );
2000
+ assertThat (resolved ).contains (lbf .getBean ("bd1" ));
2001
+ assertThat (resolved ).contains (lbf .getBean ("bd2" ));
1986
2002
}
1987
2003
1988
2004
@ Test
@@ -2378,11 +2394,20 @@ void beanProviderWithParentBeanFactoryAndMixedOrder() {
2378
2394
parentBf .registerBeanDefinition ("highPriorityTestBean" , bd2 );
2379
2395
2380
2396
ObjectProvider <TestBean > testBeanProvider = lbf .getBeanProvider (ResolvableType .forClass (TestBean .class ));
2381
- List <TestBean > resolved = testBeanProvider .orderedStream ().toList ();
2382
- assertThat (resolved ).containsExactly (
2397
+ assertThat (testBeanProvider .orderedStream ()).containsExactly (
2383
2398
lbf .getBean ("highPriorityTestBean" , TestBean .class ),
2384
2399
lbf .getBean ("lowPriorityTestBean" , TestBean .class ),
2385
2400
lbf .getBean ("plainTestBean" , TestBean .class ));
2401
+ assertThat (testBeanProvider .orderedStream (clazz -> clazz != TestBean .class ).toList ()).containsExactly (
2402
+ lbf .getBean ("highPriorityTestBean" , TestBean .class ),
2403
+ lbf .getBean ("lowPriorityTestBean" , TestBean .class ));
2404
+ assertThat (testBeanProvider .stream ()).containsExactly (
2405
+ lbf .getBean ("plainTestBean" , TestBean .class ),
2406
+ lbf .getBean ("lowPriorityTestBean" , TestBean .class ),
2407
+ lbf .getBean ("highPriorityTestBean" , TestBean .class ));
2408
+ assertThat (testBeanProvider .orderedStream (clazz -> clazz != TestBean .class ).toList ()).containsExactly (
2409
+ lbf .getBean ("lowPriorityTestBean" , TestBean .class ),
2410
+ lbf .getBean ("highPriorityTestBean" , TestBean .class ));
2386
2411
}
2387
2412
2388
2413
@ Test
0 commit comments