You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2023/02/09 16:31:47 UTC

[flex-utilities] branch develop updated: flex-sdk-converter: fix PlatformTypeTest that no longer works on JDK 12+

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/flex-utilities.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6ed6ca53 flex-sdk-converter: fix PlatformTypeTest that no longer works on JDK 12+
6ed6ca53 is described below

commit 6ed6ca530557fbc0b35e6fac51a5481324252cf5
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Feb 9 08:31:39 2023 -0800

    flex-sdk-converter: fix PlatformTypeTest that no longer works on JDK 12+
    
    Reflection is stricter and you can't make certain fields  non-final anymore
---
 .../retrievers/types/PlatformTypeTest.java         | 65 +++++-----------------
 1 file changed, 13 insertions(+), 52 deletions(-)

diff --git a/flex-maven-tools/flex-sdk-converter/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java b/flex-maven-tools/flex-sdk-converter/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java
index 1b6da4b7..ced46061 100644
--- a/flex-maven-tools/flex-sdk-converter/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java
+++ b/flex-maven-tools/flex-sdk-converter/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java
@@ -16,65 +16,26 @@
  */
 package org.apache.flex.utilities.converter.retrievers.types;
 
-import junitparams.JUnitParamsRunner;
-import junitparams.Parameters;
 import org.apache.commons.lang3.SystemUtils;
-import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.Collection;
 
 import static org.junit.Assert.assertEquals;
 
-@RunWith(JUnitParamsRunner.class)
 public class PlatformTypeTest {
 
-	private Class<SystemUtils> systemUtilsClass;
-
-	public static Collection<Object[]> platformParameters() {
-		return Arrays.asList(new Object[][]{
-				{"IS_OS_WINDOWS", PlatformType.WINDOWS},
-				{"IS_OS_MAC", PlatformType.MAC},
-				{"IS_OS_MAC_OSX", PlatformType.MAC},
-				{"IS_OS_UNIX", PlatformType.LINUX}
-		});
-	}
-
-	@Before
-	public void setUp() throws Exception {
-		systemUtilsClass = SystemUtils.class;
-
-		setFinalStatic(systemUtilsClass.getField("IS_OS_WINDOWS"), false);
-		setFinalStatic(systemUtilsClass.getField("IS_OS_MAC"), false);
-		setFinalStatic(systemUtilsClass.getField("IS_OS_MAC_OSX"), false);
-		setFinalStatic(systemUtilsClass.getField("IS_OS_UNIX"), false);
-	}
-
 	@Test
-	@Parameters(method = "platformParameters")
-	public void it_detects_the_current_platform_type(String fieldName, PlatformType platformType) throws Exception {
-
-		setFinalStatic(systemUtilsClass.getField(fieldName), true);
-		assertEquals(platformType, PlatformType.getCurrent());
-	}
-
-	@Test(expected = Exception.class)
-	public void it_throws_an_exception_when_it_can_not_detect_the_current_platform_type() throws Exception {
-		PlatformType.getCurrent();
-	}
-
-	private static void setFinalStatic(Field field, Object newValue) throws Exception {
-		field.setAccessible(true);
-
-		// remove final modifier from field
-		Field modifiersField = Field.class.getDeclaredField("modifiers");
-		modifiersField.setAccessible(true);
-		modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
-
-		field.set(null, newValue);
+	public void it_detects_the_current_platform_type() throws Exception {
+		if (SystemUtils.IS_OS_WINDOWS)
+        {
+			assertEquals(PlatformType.WINDOWS, PlatformType.getCurrent());
+        }
+        else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX)
+        {
+			assertEquals(PlatformType.MAC, PlatformType.getCurrent());
+        }
+        else if (SystemUtils.IS_OS_UNIX)
+        {
+			assertEquals(PlatformType.LINUX, PlatformType.getCurrent());
+        }
 	}
 }