Skip to content

Commit e0f012f

Browse files
committed
Removal of redundant JdkVersion checks in the test suite
Issue: SPR-13312
1 parent 6e1567b commit e0f012f

File tree

8 files changed

+69
-96
lines changed

8 files changed

+69
-96
lines changed

spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525

2626
import org.junit.Test;
2727

28-
import org.springframework.core.JdkVersion;
2928
import org.springframework.tests.sample.beans.TestBean;
3029

3130
import static org.hamcrest.CoreMatchers.equalTo;
@@ -138,7 +137,7 @@ public void standardReadAndNonStandardIndexedWriteMethod() throws IntrospectionE
138137

139138
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
140139
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
141-
assertThat(hasIndexedWriteMethodForProperty(bi, "foo"), is(trueUntilJdk17()));
140+
assertThat(hasIndexedWriteMethodForProperty(bi, "foo"), is(false));
142141

143142
BeanInfo ebi = new ExtendedBeanInfo(bi);
144143

@@ -484,7 +483,7 @@ class C {
484483

485484
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
486485
// interesting! standard Inspector picks up non-void return types on indexed write methods by default
487-
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(trueUntilJdk17()));
486+
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
488487

489488
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
490489

@@ -509,13 +508,13 @@ class C {
509508
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
510509
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
511510
// again as above, standard Inspector picks up non-void return types on indexed write methods by default
512-
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(trueUntilJdk17()));
511+
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
513512

514513
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
515514

516515
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
517516
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
518-
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(trueUntilJdk17()));
517+
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
519518

520519
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
521520
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(true));
@@ -719,19 +718,19 @@ public void reproSpr8522() throws IntrospectionException {
719718
assertThat(hasReadMethodForProperty(bi, "dateFormat"), is(false));
720719
assertThat(hasWriteMethodForProperty(bi, "dateFormat"), is(false));
721720
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat"), is(false));
722-
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(trueUntilJdk17()));
721+
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(false));
723722

724723
BeanInfo ebi = new ExtendedBeanInfo(bi);
725724

726725
assertThat(hasReadMethodForProperty(bi, "dateFormat"), is(false));
727726
assertThat(hasWriteMethodForProperty(bi, "dateFormat"), is(false));
728727
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat"), is(false));
729-
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(trueUntilJdk17()));
728+
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(false));
730729

731730
assertThat(hasReadMethodForProperty(ebi, "dateFormat"), is(false));
732731
assertThat(hasWriteMethodForProperty(ebi, "dateFormat"), is(true));
733732
assertThat(hasIndexedReadMethodForProperty(ebi, "dateFormat"), is(false));
734-
assertThat(hasIndexedWriteMethodForProperty(ebi, "dateFormat"), is(trueUntilJdk17()));
733+
assertThat(hasIndexedWriteMethodForProperty(ebi, "dateFormat"), is(false));
735734
}
736735

737736
@Test
@@ -928,10 +927,6 @@ private boolean hasIndexedReadMethodForProperty(BeanInfo beanInfo, String proper
928927
return false;
929928
}
930929

931-
private boolean trueUntilJdk17() {
932-
return JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_17;
933-
}
934-
935930

936931
interface Spr9453<T> {
937932

spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424

2525
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
2626
import org.springframework.beans.factory.support.RootBeanDefinition;
27-
import org.springframework.core.JdkVersion;
2827

2928
import static org.junit.Assert.*;
3029

@@ -36,8 +35,7 @@ public class ServiceLoaderTests {
3635

3736
@Test
3837
public void testServiceLoaderFactoryBean() {
39-
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16 ||
40-
!ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
38+
if (!ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
4139
return;
4240
}
4341

@@ -51,8 +49,7 @@ public void testServiceLoaderFactoryBean() {
5149

5250
@Test
5351
public void testServiceFactoryBean() {
54-
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16 ||
55-
!ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
52+
if (!ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
5653
return;
5754
}
5855

@@ -65,8 +62,7 @@ public void testServiceFactoryBean() {
6562

6663
@Test
6764
public void testServiceListFactoryBean() {
68-
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16 ||
69-
!ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
65+
if (!ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
7066
return;
7167
}
7268

spring-beans/src/test/java/org/springframework/beans/propertyeditors/BeanInfoTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,20 +20,22 @@
2020
import java.beans.PropertyDescriptor;
2121
import java.beans.SimpleBeanInfo;
2222

23-
import junit.framework.TestCase;
23+
import org.junit.Test;
2424

2525
import org.springframework.beans.BeanWrapper;
2626
import org.springframework.beans.BeanWrapperImpl;
2727
import org.springframework.beans.FatalBeanException;
28-
import org.springframework.core.JdkVersion;
2928
import org.springframework.util.Assert;
3029

30+
import static org.junit.Assert.*;
31+
3132
/**
3233
* @author Juergen Hoeller
3334
* @since 06.03.2006
3435
*/
35-
public class BeanInfoTests extends TestCase {
36+
public class BeanInfoTests {
3637

38+
@Test
3739
public void testComplexObject() {
3840
ValueBean bean = new ValueBean();
3941
BeanWrapper bw = new BeanWrapperImpl(bean);
@@ -99,9 +101,7 @@ public MyNumberEditor(Object target) throws IllegalArgumentException {
99101

100102
@Override
101103
public void setAsText(String text) throws IllegalArgumentException {
102-
if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
103-
Assert.isTrue(this.target instanceof ValueBean, "Target must be available on JDK 1.5+");
104-
}
104+
Assert.isTrue(this.target instanceof ValueBean, "Target must be available");
105105
super.setAsText(text);
106106
}
107107

spring-context/src/test/java/org/springframework/jmx/export/annotation/JmxUtilsAnnotationTests.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -18,35 +18,32 @@
1818

1919
import javax.management.MXBean;
2020

21-
import junit.framework.TestCase;
21+
import org.junit.Test;
2222

23-
import org.springframework.core.JdkVersion;
2423
import org.springframework.jmx.support.JmxUtils;
2524

25+
import static org.junit.Assert.*;
26+
2627
/**
2728
* @author Juergen Hoeller
2829
*/
29-
public class JmxUtilsAnnotationTests extends TestCase {
30+
public class JmxUtilsAnnotationTests {
3031

32+
@Test
3133
public void testNotMXBean() throws Exception {
32-
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
33-
return;
34-
}
3534
FooNotX foo = new FooNotX();
3635
assertFalse("MXBean annotation not detected correctly", JmxUtils.isMBean(foo.getClass()));
3736
}
3837

38+
@Test
3939
public void testAnnotatedMXBean() throws Exception {
40-
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
41-
return;
42-
}
4340
FooX foo = new FooX();
4441
assertTrue("MXBean annotation not detected correctly", JmxUtils.isMBean(foo.getClass()));
4542
}
4643

4744

4845
@MXBean(false)
49-
public static interface FooNotMXBean {
46+
public interface FooNotMXBean {
5047

5148
String getName();
5249
}
@@ -62,7 +59,7 @@ public String getName() {
6259

6360

6461
@MXBean(true)
65-
public static interface FooIfc {
62+
public interface FooIfc {
6663

6764
String getName();
6865
}

spring-context/src/test/java/org/springframework/jmx/support/JmxUtilsTests.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -25,50 +25,58 @@
2525
import javax.management.ObjectName;
2626
import javax.management.StandardMBean;
2727

28-
import junit.framework.TestCase;
28+
import org.junit.Test;
2929

3030
import org.springframework.beans.BeanWrapperImpl;
31-
import org.springframework.core.JdkVersion;
3231
import org.springframework.jmx.IJmxTestBean;
3332
import org.springframework.jmx.JmxTestBean;
3433
import org.springframework.jmx.export.TestDynamicMBean;
3534
import org.springframework.util.ObjectUtils;
3635

36+
import static org.junit.Assert.*;
37+
3738
/**
3839
* @author Rob Harrop
3940
* @author Juergen Hoeller
4041
*/
41-
public class JmxUtilsTests extends TestCase {
42+
public class JmxUtilsTests {
4243

44+
@Test
4345
public void testIsMBeanWithDynamicMBean() throws Exception {
4446
DynamicMBean mbean = new TestDynamicMBean();
4547
assertTrue("Dynamic MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
4648
}
4749

50+
@Test
4851
public void testIsMBeanWithStandardMBeanWrapper() throws Exception {
4952
StandardMBean mbean = new StandardMBean(new JmxTestBean(), IJmxTestBean.class);
5053
assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
5154
}
5255

56+
@Test
5357
public void testIsMBeanWithStandardMBeanInherited() throws Exception {
5458
StandardMBean mbean = new StandardMBeanImpl();
5559
assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
5660
}
5761

62+
@Test
5863
public void testNotAnMBean() throws Exception {
5964
assertFalse("Object incorrectly identified as an MBean", JmxUtils.isMBean(Object.class));
6065
}
6166

67+
@Test
6268
public void testSimpleMBean() throws Exception {
6369
Foo foo = new Foo();
6470
assertTrue("Simple MBean not detected correctly", JmxUtils.isMBean(foo.getClass()));
6571
}
6672

73+
@Test
6774
public void testSimpleMXBean() throws Exception {
6875
FooX foo = new FooX();
6976
assertTrue("Simple MXBean not detected correctly", JmxUtils.isMBean(foo.getClass()));
7077
}
7178

79+
@Test
7280
public void testSimpleMBeanThroughInheritance() throws Exception {
7381
Bar bar = new Bar();
7482
Abc abc = new Abc();
@@ -78,18 +86,21 @@ public void testSimpleMBeanThroughInheritance() throws Exception {
7886
JmxUtils.isMBean(abc.getClass()));
7987
}
8088

89+
@Test
8190
public void testGetAttributeNameWithStrictCasing() {
8291
PropertyDescriptor pd = new BeanWrapperImpl(AttributeTestBean.class).getPropertyDescriptor("name");
8392
String attributeName = JmxUtils.getAttributeName(pd, true);
8493
assertEquals("Incorrect casing on attribute name", "Name", attributeName);
8594
}
8695

96+
@Test
8797
public void testGetAttributeNameWithoutStrictCasing() {
8898
PropertyDescriptor pd = new BeanWrapperImpl(AttributeTestBean.class).getPropertyDescriptor("name");
8999
String attributeName = JmxUtils.getAttributeName(pd, false);
90100
assertEquals("Incorrect casing on attribute name", "name", attributeName);
91101
}
92102

103+
@Test
93104
public void testAppendIdentityToObjectName() throws MalformedObjectNameException {
94105
ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");
95106
Object managedResource = new Object();
@@ -102,11 +113,8 @@ public void testAppendIdentityToObjectName() throws MalformedObjectNameException
102113
assertEquals("Identity key is incorrect", ObjectUtils.getIdentityHexString(managedResource), uniqueName.getKeyProperty(JmxUtils.IDENTITY_OBJECT_NAME_KEY));
103114
}
104115

116+
@Test
105117
public void testLocatePlatformMBeanServer() {
106-
if(JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
107-
return;
108-
}
109-
110118
MBeanServer server = null;
111119
try {
112120
server = JmxUtils.locateMBeanServer();
@@ -118,6 +126,7 @@ public void testLocatePlatformMBeanServer() {
118126
}
119127
}
120128

129+
@Test
121130
public void testIsMBean() {
122131
// Correctly returns true for a class
123132
assertTrue(JmxUtils.isMBean(JmxClass.class));

0 commit comments

Comments
 (0)