BAEL-1749 Spring @Order
* A new rest controller has been added to demonstrate the real-time event streaming using Spring WebFlux * delete * Delete WebfluxController.java * BAEL-658 (#4150) * Review changes * BAEL-1749 Test name change
This commit is contained in:
		
							parent
							
								
									0b8f6175fe
								
							
						
					
					
						commit
						29d9b56434
					
				
							
								
								
									
										15
									
								
								spring-all/src/main/java/org/baeldung/order/Average.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								spring-all/src/main/java/org/baeldung/order/Average.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| package org.baeldung.order; | ||||
| 
 | ||||
| import org.springframework.core.Ordered; | ||||
| import org.springframework.core.annotation.Order; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| @Component | ||||
| @Order(Ordered.LOWEST_PRECEDENCE) | ||||
| public class Average implements Rating { | ||||
| 
 | ||||
|     @Override | ||||
|     public int getRating() { | ||||
|         return 3; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								spring-all/src/main/java/org/baeldung/order/Excellent.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								spring-all/src/main/java/org/baeldung/order/Excellent.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| package org.baeldung.order; | ||||
| 
 | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.core.annotation.Order; | ||||
| 
 | ||||
| @Component | ||||
| @Order(1) | ||||
| public class Excellent implements Rating { | ||||
| 
 | ||||
|     @Override | ||||
|     public int getRating() { | ||||
|         return 1; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								spring-all/src/main/java/org/baeldung/order/Good.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								spring-all/src/main/java/org/baeldung/order/Good.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| package org.baeldung.order; | ||||
| 
 | ||||
| import org.springframework.core.annotation.Order; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| @Component | ||||
| @Order(2) | ||||
| public class Good implements Rating { | ||||
| 
 | ||||
|     @Override | ||||
|     public int getRating() { | ||||
|         return 2; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										6
									
								
								spring-all/src/main/java/org/baeldung/order/Rating.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								spring-all/src/main/java/org/baeldung/order/Rating.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| package org.baeldung.order; | ||||
| 
 | ||||
| public interface Rating { | ||||
|      | ||||
|     int getRating(); | ||||
| } | ||||
| @ -0,0 +1,37 @@ | ||||
| package org.baeldung.order; | ||||
| 
 | ||||
| 
 | ||||
| import static org.hamcrest.CoreMatchers.equalTo; | ||||
| import static org.hamcrest.CoreMatchers.is; | ||||
| import static org.junit.Assert.assertThat; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.context.annotation.ComponentScan; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.test.context.ContextConfiguration; | ||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; | ||||
| 
 | ||||
| @RunWith(SpringJUnit4ClassRunner.class) | ||||
| @ContextConfiguration(loader = AnnotationConfigContextLoader.class) | ||||
| public class RatingRetrieverUnitTest { | ||||
|      | ||||
|     @Configuration  | ||||
|     @ComponentScan(basePackages = {"org.baeldung.order"})  | ||||
|     static class ContextConfiguration {}  | ||||
|      | ||||
|     @Autowired | ||||
|     private List<Rating> ratings; | ||||
|      | ||||
|     @Test | ||||
|     public void givenOrderOnComponents_whenInjected_thenAutowireByOrderValue() { | ||||
|         assertThat(ratings.get(0).getRating(), is(equalTo(1))); | ||||
|         assertThat(ratings.get(1).getRating(), is(equalTo(2))); | ||||
|         assertThat(ratings.get(2).getRating(), is(equalTo(3))); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user