You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2021/06/28 21:20:07 UTC

[trafficcontrol] branch master updated: Update Mockito to v3 and PowerMock to v2 (#5976)

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

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new b3c9d33  Update Mockito to v3 and PowerMock to v2 (#5976)
b3c9d33 is described below

commit b3c9d33e21279c445d51936a08c5403cbfc3ff7f
Author: Zach Hoffman <zr...@apache.org>
AuthorDate: Mon Jun 28 15:19:57 2021 -0600

    Update Mockito to v3 and PowerMock to v2 (#5976)
    
    * Use powermock-api-mockito2
    
    * Update to mockito-core 3 from mockito-all 1
    
    * Update deprecated method usage
    
    * Override matches() with RRset-typed argument in ArgumentMatcher implementations
    
    * Sort steering results using list.sort()
    
    * Always call real TrafficRouter.selectCachesByGeo() method
    
    * Broaden conditions for calling other real methods
    
    * Use explicit PowerMockito syntax to mock methods
    
    * Use Mockito answers for stubs requiring varying return values
    
    Co-authored-by: Rawlin Peters <ra...@apache.org>
---
 traffic_router/connector/pom.xml                   |  7 +-
 .../java/secure/CertificateDataListenerTest.java   |  2 +-
 traffic_router/core/pom.xml                        |  7 +-
 .../traffic_router/core/router/TrafficRouter.java  |  4 +-
 .../core/config/ConfigHandlerTest.java             |  4 +-
 .../core/dns/DNSAccessEventBuilderTest.java        | 85 +++++++++++++++++++---
 .../traffic_router/core/dns/NameServerTest.java    |  4 +-
 .../core/dns/ZoneManagerUnitTest.java              |  9 ++-
 .../core/dns/ZoneSignerImplTest.java               | 20 ++---
 .../core/dns/protocol/AbstractProtocolTest.java    | 25 ++++++-
 .../traffic_router/core/dns/protocol/TCPTest.java  |  2 +-
 .../traffic_router/core/dns/protocol/UDPTest.java  |  4 +-
 .../core/hashing/ConsistentHasherTest.java         |  7 +-
 .../traffic_router/core/hashing/HashableTest.java  |  3 +-
 .../core/http/HTTPAccessEventBuilderTest.java      | 49 +++++++++++--
 .../core/loc/AbstractServiceUpdaterTest.java       | 15 ++--
 .../traffic_router/core/loc/CoverageZoneTest.java  | 14 ++--
 .../core/router/DNSRoutingMissesTest.java          |  2 +-
 .../core/router/GeoSortSteeringResultsTest.java    | 16 ++--
 .../core/router/TrafficRouterTest.java             | 42 +++++------
 .../traffic_router/core/util/FetcherTest.java      |  8 +-
 traffic_router/geolocation/pom.xml                 | 10 ++-
 .../TrafficRouterConfigurationListenerTest.java    |  4 +-
 .../test/java/data/NeustarDatabaseUpdaterTest.java |  4 +-
 .../src/test/java/data/TarExtractorTest.java       |  4 +-
 traffic_router/pom.xml                             | 11 +--
 traffic_router/shared/pom.xml                      |  7 +-
 27 files changed, 257 insertions(+), 112 deletions(-)

diff --git a/traffic_router/connector/pom.xml b/traffic_router/connector/pom.xml
index 8241c1b..48cc787 100644
--- a/traffic_router/connector/pom.xml
+++ b/traffic_router/connector/pom.xml
@@ -100,17 +100,20 @@
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
-			<artifactId>powermock-api-mockito</artifactId>
+			<artifactId>powermock-api-mockito2</artifactId>
+			<version>2.0.9</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.mockito</groupId>
-			<artifactId>mockito-all</artifactId>
+			<artifactId>mockito-core</artifactId>
+			<version>3.11.1</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
 			<artifactId>powermock-module-junit4</artifactId>
+			<version>2.0.9</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
diff --git a/traffic_router/connector/src/test/java/secure/CertificateDataListenerTest.java b/traffic_router/connector/src/test/java/secure/CertificateDataListenerTest.java
index f08f53d..809537d 100644
--- a/traffic_router/connector/src/test/java/secure/CertificateDataListenerTest.java
+++ b/traffic_router/connector/src/test/java/secure/CertificateDataListenerTest.java
@@ -31,7 +31,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
diff --git a/traffic_router/core/pom.xml b/traffic_router/core/pom.xml
index 1ee498e..95fa5c8 100644
--- a/traffic_router/core/pom.xml
+++ b/traffic_router/core/pom.xml
@@ -386,17 +386,20 @@
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
-			<artifactId>powermock-api-mockito</artifactId>
+			<artifactId>powermock-api-mockito2</artifactId>
+			<version>2.0.9</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.mockito</groupId>
-			<artifactId>mockito-all</artifactId>
+			<artifactId>mockito-core</artifactId>
+			<version>3.11.1</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
 			<artifactId>powermock-module-junit4</artifactId>
+			<version>2.0.9</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
index 592272a..86ab09b 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
@@ -1665,8 +1665,8 @@ public class TrafficRouter {
 
 		final Geolocation clientLocation = getClientLocationByCoverageZoneOrGeo(clientIP, deliveryService);
 		if (clientLocation != null) {
-			Collections.sort(steeringResults, new SteeringGeolocationComparator(clientLocation));
-			Collections.sort(steeringResults, Comparator.comparingInt(s -> s.getSteeringTarget().getOrder())); // re-sort by order to preserve the ordering done by ConsistentHasher
+			steeringResults.sort(new SteeringGeolocationComparator(clientLocation));
+			steeringResults.sort(Comparator.comparingInt(s -> s.getSteeringTarget().getOrder())); // re-sort by order to preserve the ordering done by ConsistentHasher
 		}
 	}
 
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandlerTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandlerTest.java
index bdb9c99..b79841e 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandlerTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandlerTest.java
@@ -37,8 +37,8 @@ import org.junit.Test;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.doAnswer;
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/DNSAccessEventBuilderTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/DNSAccessEventBuilderTest.java
index c9a8eac..27701e8 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/DNSAccessEventBuilderTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/DNSAccessEventBuilderTest.java
@@ -21,6 +21,9 @@ import com.comcast.cdn.traffic_control.traffic_router.core.router.StatTracker.Tr
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 import org.xbill.DNS.*;
@@ -36,6 +39,7 @@ import static org.mockito.Mockito.when;
 import static org.powermock.api.mockito.PowerMockito.mockStatic;
 import static org.powermock.api.mockito.PowerMockito.spy;
 import static org.powermock.api.mockito.PowerMockito.whenNew;
+import static org.powermock.api.support.membermodification.MemberModifier.stub;
 
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({Random.class, Header.class, DNSAccessEventBuilder.class, System.class, DNSAccessRecord.class})
@@ -61,8 +65,15 @@ public class DNSAccessEventBuilderTest {
 
     @Test
     public void itCreatesRequestErrorData() throws Exception {
-        when(System.currentTimeMillis()).thenReturn(144140678789L);
-        when(System.nanoTime()).thenReturn(100000000L,889000000L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000000L,889000000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
+        when(System.currentTimeMillis()).thenAnswer(invocation -> 144140678789L);
 
         DNSAccessRecord dnsAccessRecord = new DNSAccessRecord.Builder(144140678000L, client).build();
 
@@ -75,8 +86,23 @@ public class DNSAccessEventBuilderTest {
     public void itAddsResponseData() throws Exception {
         final Name name = Name.fromString("www.example.com.");
 
-        when(System.nanoTime()).thenReturn(100000000L, 100000000L + 789123000L );
-        when(System.currentTimeMillis()).thenReturn(144140678789L).thenReturn(144140678000L);
+		Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000000L, 100000000L + 789123000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
+
+		Answer<Long> currentTimeAnswer = new Answer<Long>() {
+            final long[] currentTimes = {144140678789L, 144140678000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return currentTimes[index++ % 2];
+            }
+        };
+        when(System.currentTimeMillis()).then(currentTimeAnswer);
 
         final Record question = Record.newRecord(name, Type.A, DClass.IN, 12345L);
 
@@ -109,7 +135,7 @@ public class DNSAccessEventBuilderTest {
                 " rcode=NOERROR rtype=- rloc=\"-\" rdtl=- rerr=\"-\" ttl=\"1 2 3\" ans=\"foo bar baz\""));
 
 
-        when(System.nanoTime()).thenReturn(100000000L + 456000L);
+        when(System.nanoTime()).thenAnswer(invocation -> 100000000L + 456000L);
         dnsAccessEvent = DNSAccessEventBuilder.create(dnsAccessRecord);
 
         assertThat(dnsAccessEvent, equalTo("144140678.000 qtype=DNS chi=192.168.10.11 rhi=- ttms=0.456" +
@@ -120,8 +146,15 @@ public class DNSAccessEventBuilderTest {
     @Test
     public void itCreatesServerErrorData() throws Exception {
         Message query = Message.newQuery(Record.newRecord(Name.fromString("www.example.com."), Type.A, DClass.IN, 12345L));
-        when(System.currentTimeMillis()).thenReturn(144140678789L);
-        when(System.nanoTime()).thenReturn(100000000L, 100000000L + 789876321L );
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000000L, 100000000L + 789876321L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
+        when(System.currentTimeMillis()).thenAnswer(invocation -> 144140678789L);
 
         DNSAccessRecord dnsAccessRecord = new DNSAccessRecord.Builder(144140678000L, client).dnsMessage(query).build();
         String dnsAccessEvent = DNSAccessEventBuilder.create(dnsAccessRecord, new RuntimeException("boom it failed"));
@@ -134,8 +167,23 @@ public class DNSAccessEventBuilderTest {
     public void itAddsResultTypeData() throws Exception {
         final Name name = Name.fromString("www.example.com.");
 
-        when(System.currentTimeMillis()).thenReturn(144140678789L).thenReturn(144140678000L);
-        when(System.nanoTime()).thenReturn(100000000L, 100000000L + 789000321L, 100000000L + 123123L, 100000000L + 246001L );
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000000L, 100000000L + 789000321L, 100000000L + 123123L, 100000000L + 246001L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 4];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
+
+        Answer<Long> currentTimeAnswer = new Answer<Long>() {
+            final long[] currentTimes = {144140678789L, 144140678000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return currentTimes[index++ % 2];
+            }
+        };
+        when(System.currentTimeMillis()).then(currentTimeAnswer);
 
         final Record question = Record.newRecord(name, Type.A, DClass.IN, 12345L);
         final Message response = spy(Message.newQuery(question));
@@ -190,8 +238,23 @@ public class DNSAccessEventBuilderTest {
     public void itLogsResolverAndClient() throws Exception {
         final Name name = Name.fromString("www.example.com.");
 
-        when(System.currentTimeMillis()).thenReturn(144140678789L).thenReturn(144140678000L);
-        when(System.nanoTime()).thenReturn(100000000L, 100000000L + 789000321L, 100000000L + 123123L, 100000000L + 246001L );
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000000L, 100000000L + 789000321L, 100000000L + 123123L, 100000000L + 246001L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 4];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
+
+        Answer<Long> currentTimeAnswer = new Answer<Long>() {
+            final long[] currentTimes = {144140678789L, 144140678000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return currentTimes[index++ % 2];
+            }
+        };
+        when(System.currentTimeMillis()).then(currentTimeAnswer);
 
         final Record question = Record.newRecord(name, Type.A, DClass.IN, 12345L);
         final Message response = spy(Message.newQuery(question));
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/NameServerTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/NameServerTest.java
index 5b48aab..730d319 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/NameServerTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/NameServerTest.java
@@ -38,8 +38,8 @@ import static org.hamcrest.Matchers.equalTo;
 import java.net.Inet4Address;
 import java.net.InetAddress;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.powermock.api.mockito.PowerMockito.*;
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManagerUnitTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManagerUnitTest.java
index c5c2135..8b06ea5 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManagerUnitTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneManagerUnitTest.java
@@ -45,8 +45,8 @@ import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.*;
 import static org.powermock.api.mockito.PowerMockito.doCallRealMethod;
 import static org.powermock.api.mockito.PowerMockito.whenNew;
@@ -63,13 +63,14 @@ public class ZoneManagerUnitTest {
         when(trafficRouter.getCacheRegister()).thenReturn(cacheRegister);
 
         PowerMockito.spy(ZoneManager.class);
-        PowerMockito.doNothing().when(ZoneManager.class, "initTopLevelDomain", cacheRegister);
-        PowerMockito.doNothing().when(ZoneManager.class, "initZoneCache", trafficRouter);
+        PowerMockito.stub(PowerMockito.method(ZoneManager.class, "initTopLevelDomain")).toReturn(null);
+        PowerMockito.stub(PowerMockito.method(ZoneManager.class, "initZoneCache")).toReturn(null);
 
         SignatureManager signatureManager = PowerMockito.mock(SignatureManager.class);
         whenNew(SignatureManager.class).withArguments(any(ZoneManager.class), any(CacheRegister.class), any(TrafficOpsUtils.class), any(TrafficRouterManager.class)).thenReturn(signatureManager);
 
         zoneManager = spy(new ZoneManager(trafficRouter, new StatTracker(), null, mock(TrafficRouterManager.class)));
+
     }
 
     @Test
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneSignerImplTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneSignerImplTest.java
index f5ceb46..ebe4648 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneSignerImplTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/ZoneSignerImplTest.java
@@ -27,9 +27,9 @@ import java.util.concurrent.ConcurrentMap;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -52,15 +52,17 @@ import org.xbill.DNS.Type;
 @PrepareForTest(ZoneSignerImpl.class)
 public class ZoneSignerImplTest {
 
-    static class IsRRsetTypeA extends ArgumentMatcher<RRset> {
-        public boolean matches(Object rrset) {
-            return ((RRset) rrset).getType() == Type.A;
+    static class IsRRsetTypeA implements ArgumentMatcher<RRset> {
+        @Override
+        public boolean matches(RRset rRset) {
+            return rRset.getType() == Type.A;
         }
     }
 
-    static class IsRRsetTypeNSEC extends ArgumentMatcher<RRset> {
-        public boolean matches(Object rrset) {
-            return ((RRset) rrset).getType() == Type.NSEC;
+    static class IsRRsetTypeNSEC implements ArgumentMatcher<RRset> {
+        @Override
+        public boolean matches(RRset rRset) {
+            return rRset.getType() == Type.NSEC;
         }
     }
 
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/AbstractProtocolTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/AbstractProtocolTest.java
index f9852b4..fcb271b 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/AbstractProtocolTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/AbstractProtocolTest.java
@@ -23,6 +23,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 import org.xbill.DNS.*;
@@ -32,7 +34,7 @@ import java.net.InetAddress;
 import java.util.Random;
 
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.powermock.api.mockito.PowerMockito.*;
@@ -54,11 +56,26 @@ public class AbstractProtocolTest {
         whenNew(Random.class).withNoArguments().thenReturn(random);
 
         mockStatic(System.class);
-        when(System.currentTimeMillis()).thenReturn(144140678000L).thenReturn(144140678345L);
-        when(System.nanoTime()).thenReturn(100000000L, 100000000L + 345123000L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000000L, 100000000L + 345123000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
+
+        Answer<Long> currentTimeAnswer = new Answer<Long>() {
+            final long[] currentTimes = {144140678000L, 144140678345L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return currentTimes[index++ % 2];
+            }
+        };
+        when(System.currentTimeMillis()).then(currentTimeAnswer);
 
         mockStatic(Logger.class);
-        when(Logger.getLogger("com.comcast.cdn.traffic_control.traffic_router.core.access")).thenReturn(accessLogger);
+        when(Logger.getLogger("com.comcast.cdn.traffic_control.traffic_router.core.access")).thenAnswer(invocation -> accessLogger);
 
         header = new Header();
         header.setID(65535);
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/TCPTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/TCPTest.java
index 43e6d2d..ade8a9e 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/TCPTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/TCPTest.java
@@ -19,7 +19,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/UDPTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/UDPTest.java
index d2f19bd..32f516d 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/UDPTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/dns/protocol/UDPTest.java
@@ -18,8 +18,8 @@ package com.comcast.cdn.traffic_control.traffic_router.core.dns.protocol;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/ConsistentHasherTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/ConsistentHasherTest.java
index fe5c290..a9b0dc4 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/ConsistentHasherTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/ConsistentHasherTest.java
@@ -30,6 +30,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 
 import java.util.List;
 import java.util.ArrayList;
@@ -44,8 +45,8 @@ import static org.hamcrest.Matchers.lessThan;
 import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.mockito.MockitoAnnotations.initMocks;
@@ -87,7 +88,7 @@ public class ConsistentHasherTest {
 		when(trafficRouter.buildPatternBasedHashString(anyString(), anyString())).thenCallRealMethod();
 		when(trafficRouter.buildPatternBasedHashString(any(DeliveryService.class), any(HTTPRequest.class))).thenCallRealMethod();
 
-		initMocks(this);
+		MockitoAnnotations.openMocks(this);
 	}
 
 	@Test
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/HashableTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/HashableTest.java
index 5213c01..b175740 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/HashableTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/hashing/HashableTest.java
@@ -21,6 +21,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.core.IsNot.not;
@@ -36,7 +37,7 @@ public class HashableTest {
 
 	@Before
 	public void before() {
-		initMocks(this);
+		MockitoAnnotations.openMocks(this);
 	}
 
 	@Test
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
index 42428e9..2662e9b 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
@@ -23,6 +23,8 @@ import com.comcast.cdn.traffic_control.traffic_router.core.router.StatTracker.Tr
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
@@ -38,7 +40,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.not;
-import static org.mockito.Matchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.powermock.api.mockito.PowerMockito.mockStatic;
@@ -81,7 +83,14 @@ public class HTTPAccessEventBuilderTest {
 
     @Test
     public void itAddsResponseData() throws Exception {
-        when(System.nanoTime()).thenReturn(100111001L, 225111001L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100111001L, 225111001L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
 
         StatTracker.Track track = new StatTracker.Track();
         HTTPAccessRecord.Builder builder = new HTTPAccessRecord.Builder(new Date(144140633999L), request)
@@ -98,7 +107,14 @@ public class HTTPAccessEventBuilderTest {
 
     @Test
     public void itAddsMuiltiResponseData() throws Exception {
-        when(System.nanoTime()).thenReturn(100111001L, 225111001L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100111001L, 225111001L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
 
         List<URL> urls = new ArrayList<URL>();
         urls.add(new URL("http://example.com/hereitis/index.html?foo=bar"));
@@ -120,7 +136,14 @@ public class HTTPAccessEventBuilderTest {
 
     @Test
     public void itRoundsUpToNearestMicroSecond() throws Exception {
-        when(System.nanoTime()).thenReturn(100111001L, 100234999L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100111001L, 100234999L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
 
         Date fastFinishDate = mock(Date.class);
         when(fastFinishDate.getTime()).thenReturn(144140678000L);
@@ -141,7 +164,14 @@ public class HTTPAccessEventBuilderTest {
 
     @Test
     public void itRecordsTrafficRouterErrors() throws Exception {
-        when(System.nanoTime()).thenReturn(111001L, 567002L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {111001L, 567002L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
 
         Date fastFinishDate = mock(Date.class);
         when(fastFinishDate.getTime()).thenReturn(144140678000L);
@@ -162,7 +192,14 @@ public class HTTPAccessEventBuilderTest {
     
     @Test
     public void itRecordsMissResultDetails() throws Exception {
-        when(System.nanoTime()).thenReturn(100000101L, 100789000L);
+        Answer<Long> nanoTimeAnswer = new Answer<Long>() {
+            final long[] nanoTimes = {100000101L, 100789000L};
+            int index = 0;
+            public Long answer(InvocationOnMock invocation) {
+                return nanoTimes[index++ % 2];
+            }
+        };
+        when(System.nanoTime()).thenAnswer(nanoTimeAnswer);
 
         Date fastFinishDate = mock(Date.class);
         when(fastFinishDate.getTime()).thenReturn(144140678000L);
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdaterTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdaterTest.java
index 19898ff..f54831d 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdaterTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdaterTest.java
@@ -29,15 +29,18 @@ import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.method;
 import static org.powermock.api.mockito.PowerMockito.mockStatic;
 import static org.powermock.api.mockito.PowerMockito.whenNew;
+import static org.powermock.api.support.membermodification.MemberModifier.stub;
 
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({AbstractServiceUpdater.class, HttpURLConnection.class, URL.class, Files.class})
@@ -58,10 +61,10 @@ public class AbstractServiceUpdaterTest {
 		when(databasePath.toFile()).thenReturn(databaseFile);
 
 		databasesDirectory = mock(Path.class);
-		when(databasesDirectory.resolve(anyString())).thenReturn(databasePath);
+		when(databasesDirectory.resolve((String) isNull())).thenReturn(databasePath);
 
 		mockStatic(Files.class);
-		PowerMockito.when(Files.exists(any(Path.class))).thenReturn(true);
+		stub(method(Files.class, "exists")).toReturn(true);
 
 
 		connection = PowerMockito.mock(HttpURLConnection.class);
@@ -69,7 +72,7 @@ public class AbstractServiceUpdaterTest {
 		when(connection.getResponseCode()).thenReturn(304);
 
 		URL url = PowerMockito.mock(URL.class);
-		when(url.openConnection()).thenReturn(connection);
+		stub(method(URL.class, "openConnection")).toReturn(connection);
 
 		whenNew(URL.class).withAnyArguments().thenReturn(url);
 	}
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/CoverageZoneTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/CoverageZoneTest.java
index 4d90f67..6784440 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/CoverageZoneTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/CoverageZoneTest.java
@@ -38,9 +38,9 @@ import java.util.Set;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyListOf;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -104,11 +104,11 @@ public class CoverageZoneTest {
 		when(trafficRouter.getCoverageZoneCacheLocation("12.23.34.45", "delivery-service-1", IPVersions.IPV4ONLY)).thenCallRealMethod();
 		when(trafficRouter.getCoverageZoneCacheLocation("12.23.34.45", "delivery-service-1", false, null, IPVersions.IPV4ONLY)).thenCallRealMethod();
 		when(trafficRouter.getCacheRegister()).thenReturn(cacheRegister);
-		when(trafficRouter.orderLocations(anyListOf(CacheLocation.class),any(Geolocation.class))).thenCallRealMethod();
-		when(trafficRouter.getSupportingCaches(anyListOf(Cache.class), eq(deliveryService), any(IPVersions.class))).thenCallRealMethod();
-		when(trafficRouter.filterEnabledLocations(anyListOf(CacheLocation.class), any(CacheLocation.LocalizationMethod.class))).thenCallRealMethod();
+		when(trafficRouter.orderLocations(anyList(),any(Geolocation.class))).thenCallRealMethod();
+		when(trafficRouter.getSupportingCaches(anyList(), eq(deliveryService), any(IPVersions.class))).thenCallRealMethod();
+		when(trafficRouter.filterEnabledLocations(anyList(), any(CacheLocation.LocalizationMethod.class))).thenCallRealMethod();
 		PowerMockito.when(trafficRouter, "getNetworkNode", "12.23.34.45").thenReturn(eastNetworkNode);
-		PowerMockito.when(trafficRouter, "getClosestCacheLocation", anyListOf(CacheLocation.class), any(CacheLocation.class), any(DeliveryService.class), any(IPVersions.class)).thenCallRealMethod();
+		PowerMockito.when(trafficRouter, "getClosestCacheLocation", anyList(), any(), any(), any()).thenCallRealMethod();
 	}
 
 	@Test
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/DNSRoutingMissesTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/DNSRoutingMissesTest.java
index 9361630..93e8972 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/DNSRoutingMissesTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/DNSRoutingMissesTest.java
@@ -64,7 +64,7 @@ public class DNSRoutingMissesTest {
         trafficRouter = mock(TrafficRouter.class);
         when(trafficRouter.getCacheRegister()).thenReturn(mock(CacheRegister.class));
         Whitebox.setInternalState(trafficRouter, "federationRegistry", federationRegistry);
-        when(trafficRouter.selectCachesByGeo(anyString(), any(DeliveryService.class), any(CacheLocation.class), any(Track.class), any(IPVersions.class))).thenCallRealMethod();
+        when(trafficRouter.selectCachesByGeo(any(), any(), any(), any(), any())).thenCallRealMethod();
 
         track = spy(StatTracker.getTrack());
         doCallRealMethod().when(trafficRouter).route(request, track);
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/GeoSortSteeringResultsTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/GeoSortSteeringResultsTest.java
index 6d9d117..de86d3d 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/GeoSortSteeringResultsTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/GeoSortSteeringResultsTest.java
@@ -33,10 +33,11 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyListOf;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -54,10 +55,10 @@ public class GeoSortSteeringResultsTest {
     @Before
     public void before() {
         trafficRouter = mock(TrafficRouter.class);
-        steeringResults = new ArrayList<>();
+        steeringResults = spy(new ArrayList<>());
         clientLocation = new Geolocation(47.0, -122.0);
         deliveryService = mock(DeliveryService.class);
-        doCallRealMethod().when(trafficRouter).geoSortSteeringResults(anyListOf(SteeringResult.class), anyString(), any(DeliveryService.class));
+        doCallRealMethod().when(trafficRouter).geoSortSteeringResults(anyList(), anyString(), any(DeliveryService.class));
         when(trafficRouter.getClientLocationByCoverageZoneOrGeo(anyString(), any(DeliveryService.class))).thenReturn(clientLocation);
     }
 
@@ -85,12 +86,11 @@ public class GeoSortSteeringResultsTest {
         SteeringTarget steeringTarget = new SteeringTarget();
         steeringTarget.setGeolocation(clientLocation);
         steeringResults.add(new SteeringResult(steeringTarget, deliveryService));
-        clientLocation = null;
-        PowerMockito.mockStatic(Collections.class);
+        when(trafficRouter.getClientLocationByCoverageZoneOrGeo(anyString(), any(DeliveryService.class))).thenReturn(null);
 
         trafficRouter.geoSortSteeringResults(steeringResults, "::1", deliveryService);
 
-        PowerMockito.verifyStatic(never());
+        verify(steeringResults, never()).sort(any());
     }
 
     @Test
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
index 77815c6..bea123e 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
@@ -48,9 +48,9 @@ import java.util.HashMap;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.equalTo;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -75,14 +75,14 @@ public class TrafficRouterTest {
 
         consistentHasher = mock(ConsistentHasher.class);
 
-        when(deliveryService.createURIString(any(HTTPRequest.class), any(Cache.class))).thenReturn("http://atscache.kabletown.net/index.html");
+        when(deliveryService.createURIString(any(HTTPRequest.class), any())).thenReturn("http://atscache.kabletown.net/index.html");
 
         List<InetRecord> inetRecords = new ArrayList<InetRecord>();
         InetRecord inetRecord = new InetRecord("cname1", 12345);
         inetRecords.add(inetRecord);
 
         federationRegistry = mock(FederationRegistry.class);
-        when(federationRegistry.findInetRecords(anyString(), any(CidrAddress.class))).thenReturn(inetRecords);
+        when(federationRegistry.findInetRecords(any(), any(CidrAddress.class))).thenReturn(inetRecords);
 
         trafficRouter = mock(TrafficRouter.class);
 
@@ -98,7 +98,7 @@ public class TrafficRouterTest {
         when(trafficRouter.route(any(HTTPRequest.class), any(Track.class))).thenCallRealMethod();
         when(trafficRouter.singleRoute(any(HTTPRequest.class), any(Track.class))).thenCallRealMethod();
         when(trafficRouter.selectDeliveryService(any(Request.class))).thenReturn(deliveryService);
-        when(trafficRouter.consistentHashDeliveryService(any(DeliveryService.class), any(HTTPRequest.class), anyString())).thenCallRealMethod();
+        when(trafficRouter.consistentHashDeliveryService(any(DeliveryService.class), any(HTTPRequest.class), any())).thenCallRealMethod();
     }
 
     @Test
@@ -145,7 +145,7 @@ public class TrafficRouterTest {
         List<Cache> caches = new ArrayList<Cache>();
         caches.add(cache);
         when(trafficRouter.selectCaches(any(HTTPRequest.class), any(DeliveryService.class), any(Track.class))).thenReturn(caches);
-        when(trafficRouter.selectCachesByGeo(anyString(), any(DeliveryService.class), any(CacheLocation.class), any(Track.class), any(IPVersions.class))).thenCallRealMethod();
+        when(trafficRouter.selectCachesByGeo(any(), any(), any(), any(), any())).thenCallRealMethod();
         when(trafficRouter.getClientLocation(anyString(), any(DeliveryService.class), any(CacheLocation.class), any(Track.class))).thenReturn(new Geolocation(40, -100));
         when(trafficRouter.getCachesByGeo(any(DeliveryService.class), any(Geolocation.class), any(Track.class), any(IPVersions.class))).thenCallRealMethod();
         when(trafficRouter.getCacheRegister()).thenReturn(cacheRegister);
@@ -162,7 +162,7 @@ public class TrafficRouterTest {
         DeliveryService ds = mock(DeliveryService.class);
 
         Cache cacheIPv4 = mock(Cache.class);
-        when(cacheIPv4.hasDeliveryService(anyString())).thenReturn(true);
+        when(cacheIPv4.hasDeliveryService(any())).thenReturn(true);
         when(cacheIPv4.hasAuthority()).thenReturn(true);
         when(cacheIPv4.isAvailable(any(IPVersions.class))).thenCallRealMethod();
         doCallRealMethod().when(cacheIPv4).setIsAvailable(anyBoolean());
@@ -172,7 +172,7 @@ public class TrafficRouterTest {
         when(cacheIPv4.getId()).thenReturn("cache IPv4");
 
         Cache cacheIPv6 = mock(Cache.class);
-        when(cacheIPv6.hasDeliveryService(anyString())).thenReturn(true);
+        when(cacheIPv6.hasDeliveryService(any())).thenReturn(true);
         when(cacheIPv6.hasAuthority()).thenReturn(true);
         when(cacheIPv6.isAvailable(any(IPVersions.class))).thenCallRealMethod();
         doCallRealMethod().when(cacheIPv6).setIsAvailable(anyBoolean());
@@ -185,7 +185,7 @@ public class TrafficRouterTest {
         caches.add(cacheIPv4);
         caches.add(cacheIPv6);
 
-        when(trafficRouter.getSupportingCaches(any(List.class), any(DeliveryService.class), any(IPVersions.class))).thenCallRealMethod();
+        when(trafficRouter.getSupportingCaches(any(), any(), any())).thenCallRealMethod();
 
         List<Cache> supportingIPv4Caches = trafficRouter.getSupportingCaches(caches, ds, IPVersions.IPV4ONLY);
         assertThat(supportingIPv4Caches.size(), equalTo(1));
@@ -247,7 +247,7 @@ public class TrafficRouterTest {
     @Test
     public void itSetsResultToGeo() throws Exception {
         Cache cache = mock(Cache.class);
-        when(cache.hasDeliveryService(anyString())).thenReturn(true);
+        when(cache.hasDeliveryService(any())).thenReturn(true);
         CacheLocation cacheLocation = new CacheLocation("", new Geolocation(50,50));
 
         cacheLocation.addCache(cache);
@@ -260,19 +260,19 @@ public class TrafficRouterTest {
 
         when(trafficRouter.getCacheRegister()).thenReturn(cacheRegister);
         when(deliveryService.isLocationAvailable(cacheLocation)).thenReturn(true);
-        when(deliveryService.filterAvailableLocations(any(Collection.class))).thenCallRealMethod();
+        when(deliveryService.filterAvailableLocations(any())).thenCallRealMethod();
 
-        when(trafficRouter.selectCaches(any(HTTPRequest.class), any(DeliveryService.class), any(Track.class))).thenCallRealMethod();
-        when(trafficRouter.selectCaches(any(HTTPRequest.class), any(DeliveryService.class), any(Track.class), anyBoolean())).thenCallRealMethod();
-        when(trafficRouter.selectCachesByGeo(anyString(), any(DeliveryService.class), any(CacheLocation.class), any(Track.class), any(IPVersions.class))).thenCallRealMethod();
+        when(trafficRouter.selectCaches(any(), any(), any())).thenCallRealMethod();
+        when(trafficRouter.selectCaches(any(), any(), any(), anyBoolean())).thenCallRealMethod();
+        when(trafficRouter.selectCachesByGeo(any(), any(), any(), any(), any())).thenCallRealMethod();
 
         Geolocation clientLocation = new Geolocation(40, -100);
-        when(trafficRouter.getClientLocation(anyString(), any(DeliveryService.class), any(CacheLocation.class), any(Track.class))).thenReturn(clientLocation);
+        when(trafficRouter.getClientLocation(any(), any(), any(), any())).thenReturn(clientLocation);
 
-        when(trafficRouter.getCachesByGeo(any(DeliveryService.class), any(Geolocation.class), any(Track.class), any(IPVersions.class))).thenCallRealMethod();
-        when(trafficRouter.filterEnabledLocations(any(List.class), any(LocalizationMethod.class))).thenCallRealMethod();
-        when(trafficRouter.orderLocations(any(List.class), any(Geolocation.class))).thenCallRealMethod();
-        when(trafficRouter.getSupportingCaches(any(List.class), any(DeliveryService.class), any(IPVersions.class))).thenCallRealMethod();
+        when(trafficRouter.getCachesByGeo(any(), any(), any(), any())).thenCallRealMethod();
+        when(trafficRouter.filterEnabledLocations(any(), any())).thenCallRealMethod();
+        when(trafficRouter.orderLocations(any(), any())).thenCallRealMethod();
+        when(trafficRouter.getSupportingCaches(any(), any(), any())).thenCallRealMethod();
 
         HTTPRequest httpRequest = new HTTPRequest();
         httpRequest.setClientIP("192.168.10.11");
@@ -286,7 +286,7 @@ public class TrafficRouterTest {
         assertThat(track.getResult(), equalTo(Track.ResultType.GEO));
         assertThat(track.getResultLocation(), equalTo(new Geolocation(50, 50)));
 
-        when(federationRegistry.findInetRecords(anyString(), any(CidrAddress.class))).thenReturn(null);
+        when(federationRegistry.findInetRecords(any(), any(CidrAddress.class))).thenReturn(null);
         when(deliveryService.getRoutingName()).thenReturn("edge");
         when(deliveryService.isDns()).thenReturn(true);
 
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/util/FetcherTest.java b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/util/FetcherTest.java
index 452709d..e894c34 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/util/FetcherTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/util/FetcherTest.java
@@ -17,6 +17,7 @@ package com.comcast.cdn.traffic_control.traffic_router.core.util;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PowerMockIgnore;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
@@ -28,9 +29,12 @@ import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.method;
 import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
 import static org.powermock.api.mockito.PowerMockito.whenNew;
+import static org.powermock.api.support.membermodification.MemberModifier.stub;
 
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({Fetcher.class, URL.class, InputStreamReader.class})
@@ -53,7 +57,7 @@ public class FetcherTest {
         when(httpURLConnection.getInputStream()).thenReturn(inputStream);
 
         URL url = mock(URL.class);
-        when(url.openConnection()).thenReturn(httpURLConnection);
+        stub(method(URL.class, "openConnection")).toReturn(httpURLConnection);
         whenNew(URL.class).withArguments("http://www.example.com").thenReturn(url);
 
         Fetcher fetcher = new Fetcher();
diff --git a/traffic_router/geolocation/pom.xml b/traffic_router/geolocation/pom.xml
index 84bc30f..3201bcd 100644
--- a/traffic_router/geolocation/pom.xml
+++ b/traffic_router/geolocation/pom.xml
@@ -42,15 +42,21 @@ under the License.
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
-			<artifactId>powermock-api-mockito</artifactId>
+			<artifactId>powermock-api-mockito2</artifactId>
+			<version>2.0.9</version>
+			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.mockito</groupId>
-			<artifactId>mockito-all</artifactId>
+			<artifactId>mockito-core</artifactId>
+			<version>3.11.1</version>
+			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
 			<artifactId>powermock-module-junit4</artifactId>
+			<version>2.0.9</version>
+			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>junit</groupId>
diff --git a/traffic_router/neustar/src/test/java/configuration/TrafficRouterConfigurationListenerTest.java b/traffic_router/neustar/src/test/java/configuration/TrafficRouterConfigurationListenerTest.java
index 198e34a..6d61e3c 100644
--- a/traffic_router/neustar/src/test/java/configuration/TrafficRouterConfigurationListenerTest.java
+++ b/traffic_router/neustar/src/test/java/configuration/TrafficRouterConfigurationListenerTest.java
@@ -29,8 +29,8 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
diff --git a/traffic_router/neustar/src/test/java/data/NeustarDatabaseUpdaterTest.java b/traffic_router/neustar/src/test/java/data/NeustarDatabaseUpdaterTest.java
index 5b6e2d6..2391884 100644
--- a/traffic_router/neustar/src/test/java/data/NeustarDatabaseUpdaterTest.java
+++ b/traffic_router/neustar/src/test/java/data/NeustarDatabaseUpdaterTest.java
@@ -48,8 +48,8 @@ import java.util.zip.GZIPInputStream;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
diff --git a/traffic_router/neustar/src/test/java/data/TarExtractorTest.java b/traffic_router/neustar/src/test/java/data/TarExtractorTest.java
index 2be9efc..4b0f6b5 100644
--- a/traffic_router/neustar/src/test/java/data/TarExtractorTest.java
+++ b/traffic_router/neustar/src/test/java/data/TarExtractorTest.java
@@ -36,8 +36,8 @@ import java.io.InputStream;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
diff --git a/traffic_router/pom.xml b/traffic_router/pom.xml
index 44185c0..2ed6b1a 100644
--- a/traffic_router/pom.xml
+++ b/traffic_router/pom.xml
@@ -83,20 +83,21 @@
 			</dependency>
 			<dependency>
 				<groupId>org.powermock</groupId>
-				<artifactId>powermock-api-mockito</artifactId>
-				<version>1.6.4</version>
+				<artifactId>powermock-api-mockito2</artifactId>
+				<version>2.0.9</version>
 				<scope>test</scope>
 			</dependency>
 			<dependency>
 				<groupId>org.mockito</groupId>
-				<artifactId>mockito-all</artifactId>
-				<version>1.10.19</version>
+				<artifactId>mockito-core</artifactId>
+				<version>3.11.1</version>
 				<scope>test</scope>
 			</dependency>
 			<dependency>
 				<groupId>org.powermock</groupId>
 				<artifactId>powermock-module-junit4</artifactId>
-				<version>1.6.4</version>
+				<version>2.0.9</version>
+				<scope>test</scope>
 			</dependency>
 			<dependency>
 				<groupId>junit</groupId>
diff --git a/traffic_router/shared/pom.xml b/traffic_router/shared/pom.xml
index f4a1118..d05307e 100644
--- a/traffic_router/shared/pom.xml
+++ b/traffic_router/shared/pom.xml
@@ -80,17 +80,20 @@ under the License.
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
-			<artifactId>powermock-api-mockito</artifactId>
+			<artifactId>powermock-api-mockito2</artifactId>
+			<version>2.0.9</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.mockito</groupId>
-			<artifactId>mockito-all</artifactId>
+			<artifactId>mockito-core</artifactId>
+			<version>3.11.1</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.powermock</groupId>
 			<artifactId>powermock-module-junit4</artifactId>
+			<version>2.0.9</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>