From e40e2b7cae444af5e91a67b5123a9cb7cde839ae Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 26 Nov 2012 16:34:05 +0100 Subject: [PATCH] Introduce AnnotationAwareOrderComparator#INSTANCE Prior to this change, the INSTANCE constant one could refer to on AnnotationAwareOrderComparator actually referred to the constant declared in the OrderAwareComparator superclass. Thus AnnotationAwareOrderComparator#INSTANCE did not actually return an AnnotationAwareOrderComparator but an OrderAwareComparator instead. This commit introduces a dedicated constant on AnnotationAwareOrderComparator to avoid this glitch. Issue: SPR-10038 --- .../AnnotationAwareOrderComparator.java | 5 ++- .../AnnotationAwareOrderComparatorTests.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 spring-core/src/test/java/org/springframework/core/annotation/AnnotationAwareOrderComparatorTests.java diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java index 13a50b910dc..17f403029a7 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2012 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. @@ -27,12 +27,15 @@ import org.springframework.core.Ordered; * annotation value (if any). * * @author Juergen Hoeller + * @author Oliver Gierke * @since 2.0.1 * @see org.springframework.core.Ordered * @see Order */ public class AnnotationAwareOrderComparator extends OrderComparator { + public static AnnotationAwareOrderComparator INSTANCE = new AnnotationAwareOrderComparator(); + @Override protected int getOrder(Object obj) { if (obj instanceof Ordered) { diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAwareOrderComparatorTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAwareOrderComparatorTests.java new file mode 100644 index 00000000000..0a3e64f98e7 --- /dev/null +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAwareOrderComparatorTests.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012 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.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; + +/** + * Unit tests for {@link AnnotationAwareOrderComparator}. + * + * @author Oliver Gierke + */ +public class AnnotationAwareOrderComparatorTests { + + @Test + public void instanceVariableIsAnAnnotationAwareOrderComparator() { + assertThat(AnnotationAwareOrderComparator.INSTANCE, is(instanceOf(AnnotationAwareOrderComparator.class))); + } +}