Exemplo n.º 1
0
 public void testJavaVersionAtLeastFloat() {
   float version = SystemUtils.JAVA_VERSION_FLOAT;
   assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
   version -= 0.1f;
   assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
   version += 0.2f;
   assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
 }
Exemplo n.º 2
0
 public void testJavaVersionAtLeastInt() {
   int version = SystemUtils.JAVA_VERSION_INT;
   assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
   version -= 10;
   assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
   version += 20;
   assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
 }
Exemplo n.º 3
0
 public void testJavaAwtHeadless() {
   boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(140);
   String expectedStringValue = System.getProperty("java.awt.headless");
   String expectedStringValueWithDefault = System.getProperty("java.awt.headless", "false");
   assertNotNull(expectedStringValueWithDefault);
   if (atLeastJava14) {
     boolean expectedValue = Boolean.valueOf(expectedStringValue).booleanValue();
     if (expectedStringValue != null) {
       assertEquals(expectedStringValue, SystemUtils.JAVA_AWT_HEADLESS);
     }
     assertEquals(expectedValue, SystemUtils.isJavaAwtHeadless());
   } else {
     assertNull(expectedStringValue);
     assertNull(SystemUtils.JAVA_AWT_HEADLESS);
     assertEquals(expectedStringValueWithDefault, "" + SystemUtils.isJavaAwtHeadless());
   }
   assertEquals(expectedStringValueWithDefault, "" + SystemUtils.isJavaAwtHeadless());
 }
Exemplo n.º 4
0
 /**
  * Checks if one {@code Class} can be assigned to a variable of another {@code Class}.
  *
  * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this method takes into
  * account widenings of primitive classes and {@code null}s.
  *
  * <p>Primitive widenings allow an int to be assigned to a long, float or double. This method
  * returns the correct result for these cases.
  *
  * <p>{@code Null} may be assigned to any reference type. This method will return {@code true} if
  * {@code null} is passed in and the toClass is non-primitive.
  *
  * <p>Specifically, this method tests whether the type represented by the specified {@code Class}
  * parameter can be converted to the type represented by this {@code Class} object via an identity
  * conversion widening primitive or widening reference conversion. See <em><a
  * href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em>, sections
  * 5.1.1, 5.1.2 and 5.1.4 for details.
  *
  * <p><strong>Since Lang 3.0,</strong> this method will default behavior for calculating
  * assignability between primitive and wrapper types <em>corresponding to the running Java
  * version</em>; i.e. autoboxing will be the default behavior in VMs running Java versions &gt;
  * 1.5.
  *
  * @param cls the Class to check, may be null
  * @param toClass the Class to try to assign into, returns false if null
  * @return {@code true} if assignment possible
  */
 public static boolean isAssignable(final Class<?> cls, final Class<?> toClass) {
   return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));
 }