diff --git a/NOTICE.md b/NOTICE.md
index 021950a4b08c..c64671976e4a 100644
--- a/NOTICE.md
+++ b/NOTICE.md
@@ -321,18 +321,6 @@
war |
Mozilla Public License 2.0 with Healthcare Disclaimer |
-org.powermock |
-powermock-api-mockito |
-1.6.6 |
-jar |
-The Apache Software License, Version 2.0 |
-
-org.powermock |
-powermock-module-junit4 |
-1.6.6 |
-jar |
-The Apache Software License, Version 2.0 |
-
org.slf4j |
jcl-over-slf4j |
1.6.0 |
diff --git a/api/pom.xml b/api/pom.xml
index e47aae817a64..1e4fe3281b08 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -28,22 +28,6 @@
openmrs-test
pom
test
-
-
- org.powermock
- powermock-module-junit4
-
-
- org.powermock
- powermock-api-mockito2
-
-
-
-
- org.powermock
- powermock-reflect
- 2.0.9
- test
commons-collections
diff --git a/api/src/test/java/org/openmrs/liquibase/ChangeLogDetectiveDatabaseIT.java b/api/src/test/java/org/openmrs/liquibase/ChangeLogDetectiveDatabaseIT.java
index eb4c5db08774..0fcdf3c7c817 100644
--- a/api/src/test/java/org/openmrs/liquibase/ChangeLogDetectiveDatabaseIT.java
+++ b/api/src/test/java/org/openmrs/liquibase/ChangeLogDetectiveDatabaseIT.java
@@ -9,11 +9,11 @@
*/
package org.openmrs.liquibase;
+import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.openmrs.util.DatabaseIT;
-import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +48,9 @@ public void shouldGetInitialLiquibaseSnapshotVersion() throws Exception {
public void shouldReturnDefaultSnapshotVersion() throws Exception {
ChangeLogDetective changeLogDetective = ChangeLogDetective.getInstance();
- Whitebox.setInternalState(changeLogDetective, "initialSnapshotVersion", (Object)null);
+ Field field = ChangeLogDetective.class.getDeclaredField("initialSnapshotVersion");
+ field.setAccessible(true);
+ field.set(changeLogDetective, null);
String expected = VERSION_1_9_X;
String actual = changeLogDetective.getInitialLiquibaseSnapshotVersion("some context", this);
diff --git a/api/src/test/java/org/openmrs/module/ModuleUtilTest.java b/api/src/test/java/org/openmrs/module/ModuleUtilTest.java
index 2d4fd8fd0e45..e2f0482784e3 100644
--- a/api/src/test/java/org/openmrs/module/ModuleUtilTest.java
+++ b/api/src/test/java/org/openmrs/module/ModuleUtilTest.java
@@ -25,6 +25,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
@@ -42,7 +44,6 @@
import org.openmrs.api.context.Context;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
import org.openmrs.util.OpenmrsConstants;
-import org.powermock.reflect.Whitebox;
/**
* Tests methods on the {@link org.openmrs.module.ModuleUtil} class
@@ -120,7 +121,7 @@ public void isOpenmrsVersionInVersions_shouldReturnTrueIfCurrentOpenmrsVersionMa
throws Exception {
final String currentVersion = "1.9.8";
- Whitebox.setInternalState(OpenmrsConstants.class, "OPENMRS_VERSION_SHORT", currentVersion);
+ setFinalStaticField(OpenmrsConstants.class, "OPENMRS_VERSION_SHORT", currentVersion);
assertTrue(ModuleUtil.isOpenmrsVersionInVersions( currentVersion, "1.10.*"));
}
@@ -131,7 +132,7 @@ public void isOpenmrsVersionInVersions_shouldReturnTrueIfCurrentOpenmrsVersionMa
public void isOpenmrsVersionInVersions_shouldReturnFalseIfCurrentOpenmrsVersionDoesNotMatchAnyElementInVersions()
throws Exception {
- Whitebox.setInternalState(OpenmrsConstants.class, "OPENMRS_VERSION_SHORT", "1.9.8");
+ setFinalStaticField(OpenmrsConstants.class, "OPENMRS_VERSION_SHORT", "1.9.8");
assertFalse(ModuleUtil.isOpenmrsVersionInVersions("1.11.*", "2.1.0"));
}
@@ -814,4 +815,17 @@ protected File getEmptyJarDestinationFolder() throws IOException {
}
return destinationFolder;
}
+
+ private static void setFinalStaticField(Class> clazz, String fieldName, Object value) throws Exception {
+ Class> unsafeClass = Class.forName("sun.misc.Unsafe");
+ Field unsafeField = unsafeClass.getDeclaredField("theUnsafe");
+ unsafeField.setAccessible(true);
+ Object unsafe = unsafeField.get(null);
+
+ Field field = clazz.getDeclaredField(fieldName);
+ field.setAccessible(true);
+
+ unsafeClass.getMethod("putObjectVolatile", Object.class, long.class, Object.class)
+ .invoke(unsafe, clazz, unsafeClass.getMethod("staticFieldOffset", Field.class).invoke(unsafe, field), value);
+ }
}
diff --git a/api/src/test/java/org/openmrs/test/TestUtil.java b/api/src/test/java/org/openmrs/test/TestUtil.java
index 31b765010e55..f9a3a27c89ff 100644
--- a/api/src/test/java/org/openmrs/test/TestUtil.java
+++ b/api/src/test/java/org/openmrs/test/TestUtil.java
@@ -11,6 +11,8 @@
import java.io.FileInputStream;
import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.text.ParseException;
import java.util.Collection;
diff --git a/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java b/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java
index d96bb91b87d4..bfcba558492b 100644
--- a/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java
+++ b/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java
@@ -14,8 +14,8 @@
import org.junit.jupiter.api.Test;
import org.openmrs.liquibase.ChangeLogDetective;
import org.openmrs.liquibase.ChangeLogVersionFinder;
-import org.powermock.reflect.Whitebox;
+import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
@@ -48,9 +48,16 @@ public void tearDown() {
@Test
public void should() throws Exception {
-
- Whitebox.setInternalState(ChangeLogDetective.getInstance(), "initialSnapshotVersion", (Object)null);
- Whitebox.setInternalState(ChangeLogDetective.getInstance(), "unrunLiquibaseUpdates", (Object)null);
+ {
+ Field field = ChangeLogDetective.class.getDeclaredField("initialSnapshotVersion");
+ field.setAccessible(true);
+ field.set(ChangeLogDetective.getInstance(), null);
+ }
+ {
+ Field field = ChangeLogDetective.class.getDeclaredField("initialSnapshotVersion");
+ field.setAccessible(true);
+ field.set(ChangeLogDetective.getInstance(), null);
+ }
ChangeLogVersionFinder changeLogVersionFinder = new ChangeLogVersionFinder();
Map> snapshotCombinations = changeLogVersionFinder.getSnapshotCombinations();
diff --git a/pom.xml b/pom.xml
index 6c3b5366d705..990ddac9e795 100644
--- a/pom.xml
+++ b/pom.xml
@@ -480,16 +480,6 @@
mockito-core
${mockitoVersion}
-
- org.powermock
- powermock-module-junit4
- 2.0.9
-
-
- org.powermock
- powermock-api-mockito2
- 2.0.9
-