javax.annotation.Priority alternative to @Order

This commit rationalizes the use of @Order so that the standard
@Priority annotation can be used instead. The handling of both
annotations are now defined in OrderUtils.

This also updates the link to the JavaEE API so that we refer to
JavaEE7 instead of JavaEE6.

Issue: SPR-11639
This commit is contained in:
Stephane Nicoll
2014-04-01 14:30:47 +02:00
parent 5fe8f52c02
commit dcf5f4a6a3
12 changed files with 211 additions and 61 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -24,6 +24,8 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import javax.annotation.Priority;
/**
* @author Juergen Hoeller
* @author Oliver Gierke
@@ -45,6 +47,26 @@ public class AnnotationAwareOrderComparatorTests {
assertTrue(list.get(1) instanceof B);
}
@Test
public void sortInstancesWithPriority() {
List<Object> list = new ArrayList<>();
list.add(new B2());
list.add(new A2());
AnnotationAwareOrderComparator.sort(list);
assertTrue(list.get(0) instanceof A2);
assertTrue(list.get(1) instanceof B2);
}
@Test
public void sortInstancesWithOrderAndPriority() {
List<Object> list = new ArrayList<>();
list.add(new B());
list.add(new A2());
AnnotationAwareOrderComparator.sort(list);
assertTrue(list.get(0) instanceof A2);
assertTrue(list.get(1) instanceof B);
}
@Test
public void sortInstancesWithSubclass() {
List<Object> list = new ArrayList<>();
@@ -87,4 +109,12 @@ public class AnnotationAwareOrderComparatorTests {
private static class C extends A {
}
@Priority(1)
private static class A2 {
}
@Priority(2)
private static class B2 {
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2002-2014 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
*
* http://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.core.annotation;
import static org.junit.Assert.*;
import javax.annotation.Priority;
import org.junit.Test;
/**
*
* @author Stephane Nicoll
*/
public class OrderUtilsTests {
@Test
public void getSimpleOrder() {
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null));
}
@Test
public void getPriorityOrder() {
assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null));
}
@Test
public void getOrderWithBoth() {
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null));
}
@Test
public void getDefaultOrder() {
assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33));
}
@Test
public void getPriorityValueNoAnnotation() {
assertNull(OrderUtils.getPriorityValue(SimpleOrder.class));
}
@Test
public void getPriorityValue() {
assertEquals(Integer.valueOf(55), OrderUtils.getPriorityValue(OrderAndPriority.class));
}
@Order(50)
private static class SimpleOrder {}
@Priority(55)
private static class SimplePriority {}
@Order(50)
@Priority(55)
private static class OrderAndPriority {}
private static class NoOrder {}
}