Java Code Examples for org.apache.commons.lang.SystemUtils#isJavaVersionAtLeast()
The following examples show how to use
org.apache.commons.lang.SystemUtils#isJavaVersionAtLeast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceCodeDisclosureWEBINF.java From zap-extensions with Apache License 2.0 | 5 votes |
@Override public void init() { // Does not work with Java 9+ // https://github.com/zaproxy/zaproxy/issues/4038 if (SystemUtils.isJavaVersionAtLeast(1.9f)) { getParent() .pluginSkipped( this, Constant.messages.getString( "ascanrules.sourcecodedisclosurewebinf.skipJava9")); } }
Example 2
Source File: NumberUtilsTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testCreateNumber() { // a lot of things can go wrong assertEquals("createNumber(String) 1 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5")); assertEquals("createNumber(String) 2 failed", new Integer("12345"), NumberUtils.createNumber("12345")); assertEquals("createNumber(String) 3 failed", new Double("1234.5"), NumberUtils.createNumber("1234.5D")); assertEquals("createNumber(String) 3 failed", new Double("1234.5"), NumberUtils.createNumber("1234.5d")); assertEquals("createNumber(String) 4 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5F")); assertEquals("createNumber(String) 4 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5f")); assertEquals("createNumber(String) 5 failed", new Long(Integer.MAX_VALUE + 1L), NumberUtils.createNumber("" + (Integer.MAX_VALUE + 1L))); assertEquals("createNumber(String) 6 failed", new Long(12345), NumberUtils.createNumber("12345L")); assertEquals("createNumber(String) 6 failed", new Long(12345), NumberUtils.createNumber("12345l")); assertEquals("createNumber(String) 7 failed", new Float("-1234.5"), NumberUtils.createNumber("-1234.5")); assertEquals("createNumber(String) 8 failed", new Integer("-12345"), NumberUtils.createNumber("-12345")); assertTrue("createNumber(String) 9 failed", 0xFADE == NumberUtils.createNumber("0xFADE").intValue()); assertTrue("createNumber(String) 10 failed", -0xFADE == NumberUtils.createNumber("-0xFADE").intValue()); assertEquals("createNumber(String) 11 failed", new Double("1.1E200"), NumberUtils.createNumber("1.1E200")); assertEquals("createNumber(String) 12 failed", new Float("1.1E20"), NumberUtils.createNumber("1.1E20")); assertEquals("createNumber(String) 13 failed", new Double("-1.1E200"), NumberUtils.createNumber("-1.1E200")); assertEquals("createNumber(String) 14 failed", new Double("1.1E-200"), NumberUtils.createNumber("1.1E-200")); assertEquals("createNumber(null) failed", null, NumberUtils.createNumber(null)); assertEquals("createNumber(String) failed", new BigInteger("12345678901234567890"), NumberUtils .createNumber("12345678901234567890L")); // jdk 1.2 doesn't support this. unsure about jdk 1.2.2 if (SystemUtils.isJavaVersionAtLeast(1.3f)) { assertEquals("createNumber(String) 15 failed", new BigDecimal("1.1E-700"), NumberUtils .createNumber("1.1E-700F")); } assertEquals("createNumber(String) 16 failed", new Long("10" + Integer.MAX_VALUE), NumberUtils .createNumber("10" + Integer.MAX_VALUE + "L")); assertEquals("createNumber(String) 17 failed", new Long("10" + Integer.MAX_VALUE), NumberUtils .createNumber("10" + Integer.MAX_VALUE)); assertEquals("createNumber(String) 18 failed", new BigInteger("10" + Long.MAX_VALUE), NumberUtils .createNumber("10" + Long.MAX_VALUE)); }
Example 3
Source File: ExceptionUtilsTestCase.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetCause() { Exception cause = new ExceptionWithoutCause(); assertEquals(true, ExceptionUtils.setCause(new ExceptionWithCause(null), cause)); if (SystemUtils.isJavaVersionAtLeast(140)) { assertEquals(true, ExceptionUtils.setCause(new ExceptionWithoutCause(), cause)); } }
Example 4
Source File: ExceptionUtilsTestCase.java From astor with GNU General Public License v2.0 | 5 votes |
public void testIsThrowableNested() { if (SystemUtils.isJavaVersionAtLeast(140)) { assertEquals(true, ExceptionUtils.isThrowableNested()); } else { assertEquals(false, ExceptionUtils.isThrowableNested()); } }
Example 5
Source File: ExceptionUtilsTestCase.java From astor with GNU General Public License v2.0 | 5 votes |
public void testIsNestedThrowable_Throwable() { assertEquals(true, ExceptionUtils.isNestedThrowable(new SQLException())); assertEquals(true, ExceptionUtils.isNestedThrowable(new InvocationTargetException(new Exception()))); assertEquals(true, ExceptionUtils.isNestedThrowable(new NestableRuntimeException())); assertEquals(true, ExceptionUtils.isNestedThrowable(withCause)); assertEquals(true, ExceptionUtils.isNestedThrowable(nested)); if (SystemUtils.isJavaVersionAtLeast(140)) { assertEquals(true, ExceptionUtils.isNestedThrowable(withoutCause)); assertEquals(true, ExceptionUtils.isNestedThrowable(new Throwable())); } else { assertEquals(false, ExceptionUtils.isNestedThrowable(withoutCause)); assertEquals(false, ExceptionUtils.isNestedThrowable(new Throwable())); } }
Example 6
Source File: NumberUtilsTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testCreateNumber() { // a lot of things can go wrong assertEquals("createNumber(String) 1 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5")); assertEquals("createNumber(String) 2 failed", new Integer("12345"), NumberUtils.createNumber("12345")); assertEquals("createNumber(String) 3 failed", new Double("1234.5"), NumberUtils.createNumber("1234.5D")); assertEquals("createNumber(String) 3 failed", new Double("1234.5"), NumberUtils.createNumber("1234.5d")); assertEquals("createNumber(String) 4 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5F")); assertEquals("createNumber(String) 4 failed", new Float("1234.5"), NumberUtils.createNumber("1234.5f")); assertEquals("createNumber(String) 5 failed", new Long(Integer.MAX_VALUE + 1L), NumberUtils.createNumber("" + (Integer.MAX_VALUE + 1L))); assertEquals("createNumber(String) 6 failed", new Long(12345), NumberUtils.createNumber("12345L")); assertEquals("createNumber(String) 6 failed", new Long(12345), NumberUtils.createNumber("12345l")); assertEquals("createNumber(String) 7 failed", new Float("-1234.5"), NumberUtils.createNumber("-1234.5")); assertEquals("createNumber(String) 8 failed", new Integer("-12345"), NumberUtils.createNumber("-12345")); assertTrue("createNumber(String) 9 failed", 0xFADE == NumberUtils.createNumber("0xFADE").intValue()); assertTrue("createNumber(String) 10 failed", -0xFADE == NumberUtils.createNumber("-0xFADE").intValue()); assertEquals("createNumber(String) 11 failed", new Double("1.1E200"), NumberUtils.createNumber("1.1E200")); assertEquals("createNumber(String) 12 failed", new Float("1.1E20"), NumberUtils.createNumber("1.1E20")); assertEquals("createNumber(String) 13 failed", new Double("-1.1E200"), NumberUtils.createNumber("-1.1E200")); assertEquals("createNumber(String) 14 failed", new Double("1.1E-200"), NumberUtils.createNumber("1.1E-200")); assertEquals("createNumber(null) failed", null, NumberUtils.createNumber(null)); assertEquals("createNumber(String) failed", new BigInteger("12345678901234567890"), NumberUtils .createNumber("12345678901234567890L")); // jdk 1.2 doesn't support this. unsure about jdk 1.2.2 if (SystemUtils.isJavaVersionAtLeast(1.3f)) { assertEquals("createNumber(String) 15 failed", new BigDecimal("1.1E-700"), NumberUtils .createNumber("1.1E-700F")); } assertEquals("createNumber(String) 16 failed", new Long("10" + Integer.MAX_VALUE), NumberUtils .createNumber("10" + Integer.MAX_VALUE + "L")); assertEquals("createNumber(String) 17 failed", new Long("10" + Integer.MAX_VALUE), NumberUtils .createNumber("10" + Integer.MAX_VALUE)); assertEquals("createNumber(String) 18 failed", new BigInteger("10" + Long.MAX_VALUE), NumberUtils .createNumber("10" + Long.MAX_VALUE)); }
Example 7
Source File: ExceptionUtilsTestCase.java From astor with GNU General Public License v2.0 | 5 votes |
public void testSetCause() { Exception cause = new ExceptionWithoutCause(); assertEquals(true, ExceptionUtils.setCause(new ExceptionWithCause(null), cause)); if (SystemUtils.isJavaVersionAtLeast(140)) { assertEquals(true, ExceptionUtils.setCause(new ExceptionWithoutCause(), cause)); } }
Example 8
Source File: ExceptionUtilsTestCase.java From astor with GNU General Public License v2.0 | 5 votes |
public void testIsThrowableNested() { if (SystemUtils.isJavaVersionAtLeast(140)) { assertEquals(true, ExceptionUtils.isThrowableNested()); } else { assertEquals(false, ExceptionUtils.isThrowableNested()); } }
Example 9
Source File: ExceptionUtilsTestCase.java From astor with GNU General Public License v2.0 | 5 votes |
public void testIsNestedThrowable_Throwable() { assertEquals(true, ExceptionUtils.isNestedThrowable(new SQLException())); assertEquals(true, ExceptionUtils.isNestedThrowable(new InvocationTargetException(new Exception()))); assertEquals(true, ExceptionUtils.isNestedThrowable(new NestableRuntimeException())); assertEquals(true, ExceptionUtils.isNestedThrowable(withCause)); assertEquals(true, ExceptionUtils.isNestedThrowable(nested)); if (SystemUtils.isJavaVersionAtLeast(140)) { assertEquals(true, ExceptionUtils.isNestedThrowable(withoutCause)); assertEquals(true, ExceptionUtils.isNestedThrowable(new Throwable())); } else { assertEquals(false, ExceptionUtils.isNestedThrowable(withoutCause)); assertEquals(false, ExceptionUtils.isNestedThrowable(new Throwable())); } }
Example 10
Source File: DateUtilsTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests for LANG-59 * * see http://issues.apache.org/jira/browse/LANG-59 */ public void testTruncateLang59() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(1.4f)) { this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_VERSION); return; } // Set TimeZone to Mountain Time TimeZone MST_MDT = TimeZone.getTimeZone("MST7MDT"); TimeZone.setDefault(MST_MDT); DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); format.setTimeZone(MST_MDT); Date oct31_01MDT = new Date(1099206000000L); Date oct31MDT = new Date(oct31_01MDT.getTime() - 3600000L); // - 1 hour Date oct31_01_02MDT = new Date(oct31_01MDT.getTime() + 120000L); // + 2 minutes Date oct31_01_02_03MDT = new Date(oct31_01_02MDT.getTime() + 3000L); // + 3 seconds Date oct31_01_02_03_04MDT = new Date(oct31_01_02_03MDT.getTime() + 4L); // + 4 milliseconds assertEquals("Check 00:00:00.000", "2004-10-31 00:00:00.000 MDT", format.format(oct31MDT)); assertEquals("Check 01:00:00.000", "2004-10-31 01:00:00.000 MDT", format.format(oct31_01MDT)); assertEquals("Check 01:02:00.000", "2004-10-31 01:02:00.000 MDT", format.format(oct31_01_02MDT)); assertEquals("Check 01:02:03.000", "2004-10-31 01:02:03.000 MDT", format.format(oct31_01_02_03MDT)); assertEquals("Check 01:02:03.004", "2004-10-31 01:02:03.004 MDT", format.format(oct31_01_02_03_04MDT)); // ------- Demonstrate Problem ------- Calendar gval = Calendar.getInstance(); gval.setTime(new Date(oct31_01MDT.getTime())); gval.set(Calendar.MINUTE, gval.get(Calendar.MINUTE)); // set minutes to the same value assertEquals("Demonstrate Problem", gval.getTime().getTime(), oct31_01MDT.getTime() + 3600000L); // ---------- Test Truncate ---------- assertEquals("Truncate Calendar.MILLISECOND", oct31_01_02_03_04MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.MILLISECOND)); assertEquals("Truncate Calendar.SECOND", oct31_01_02_03MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.SECOND)); assertEquals("Truncate Calendar.MINUTE", oct31_01_02MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.MINUTE)); assertEquals("Truncate Calendar.HOUR_OF_DAY", oct31_01MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.HOUR_OF_DAY)); assertEquals("Truncate Calendar.HOUR", oct31_01MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.HOUR)); assertEquals("Truncate Calendar.DATE", oct31MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.DATE)); // ---------- Test Round (down) ---------- assertEquals("Round Calendar.MILLISECOND", oct31_01_02_03_04MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.MILLISECOND)); assertEquals("Round Calendar.SECOND", oct31_01_02_03MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.SECOND)); assertEquals("Round Calendar.MINUTE", oct31_01_02MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.MINUTE)); assertEquals("Round Calendar.HOUR_OF_DAY", oct31_01MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.HOUR_OF_DAY)); assertEquals("Round Calendar.HOUR", oct31_01MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.HOUR)); assertEquals("Round Calendar.DATE", oct31MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.DATE)); // restore default time zone TimeZone.setDefault(defaultZone); }
Example 11
Source File: DateUtilsTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests for LANG-59 * * see http://issues.apache.org/jira/browse/LANG-59 */ public void testTruncateLang59() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(1.4f)) { this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_VERSION); return; } // Set TimeZone to Mountain Time TimeZone MST_MDT = TimeZone.getTimeZone("MST7MDT"); TimeZone.setDefault(MST_MDT); DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); format.setTimeZone(MST_MDT); Date oct31_01MDT = new Date(1099206000000L); Date oct31MDT = new Date(oct31_01MDT.getTime() - 3600000L); // - 1 hour Date oct31_01_02MDT = new Date(oct31_01MDT.getTime() + 120000L); // + 2 minutes Date oct31_01_02_03MDT = new Date(oct31_01_02MDT.getTime() + 3000L); // + 3 seconds Date oct31_01_02_03_04MDT = new Date(oct31_01_02_03MDT.getTime() + 4L); // + 4 milliseconds assertEquals("Check 00:00:00.000", "2004-10-31 00:00:00.000 MDT", format.format(oct31MDT)); assertEquals("Check 01:00:00.000", "2004-10-31 01:00:00.000 MDT", format.format(oct31_01MDT)); assertEquals("Check 01:02:00.000", "2004-10-31 01:02:00.000 MDT", format.format(oct31_01_02MDT)); assertEquals("Check 01:02:03.000", "2004-10-31 01:02:03.000 MDT", format.format(oct31_01_02_03MDT)); assertEquals("Check 01:02:03.004", "2004-10-31 01:02:03.004 MDT", format.format(oct31_01_02_03_04MDT)); // ------- Demonstrate Problem ------- Calendar gval = Calendar.getInstance(); gval.setTime(new Date(oct31_01MDT.getTime())); gval.set(Calendar.MINUTE, gval.get(Calendar.MINUTE)); // set minutes to the same value assertEquals("Demonstrate Problem", gval.getTime().getTime(), oct31_01MDT.getTime() + 3600000L); // ---------- Test Truncate ---------- assertEquals("Truncate Calendar.MILLISECOND", oct31_01_02_03_04MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.MILLISECOND)); assertEquals("Truncate Calendar.SECOND", oct31_01_02_03MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.SECOND)); assertEquals("Truncate Calendar.MINUTE", oct31_01_02MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.MINUTE)); assertEquals("Truncate Calendar.HOUR_OF_DAY", oct31_01MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.HOUR_OF_DAY)); assertEquals("Truncate Calendar.HOUR", oct31_01MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.HOUR)); assertEquals("Truncate Calendar.DATE", oct31MDT, DateUtils.truncate(oct31_01_02_03_04MDT, Calendar.DATE)); // ---------- Test Round (down) ---------- assertEquals("Round Calendar.MILLISECOND", oct31_01_02_03_04MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.MILLISECOND)); assertEquals("Round Calendar.SECOND", oct31_01_02_03MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.SECOND)); assertEquals("Round Calendar.MINUTE", oct31_01_02MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.MINUTE)); assertEquals("Round Calendar.HOUR_OF_DAY", oct31_01MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.HOUR_OF_DAY)); assertEquals("Round Calendar.HOUR", oct31_01MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.HOUR)); assertEquals("Round Calendar.DATE", oct31MDT, DateUtils.round(oct31_01_02_03_04MDT, Calendar.DATE)); // restore default time zone TimeZone.setDefault(defaultZone); }