diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/field/TestFieldScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/field/TestFieldScreenPresenter.java index 18211ee2463..b6de2356401 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/field/TestFieldScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/field/TestFieldScreenPresenter.java @@ -42,7 +42,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/help/TestHelpScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/help/TestHelpScreenPresenter.java index d6f21749897..293f103e7d9 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/help/TestHelpScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/help/TestHelpScreenPresenter.java @@ -32,7 +32,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/mode/TestModeScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/mode/TestModeScreenPresenter.java index c4984966c79..8202f5d64cb 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/mode/TestModeScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/mode/TestModeScreenPresenter.java @@ -35,7 +35,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestFilterDisplayModeScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestFilterDisplayModeScreenPresenter.java index a79bcbd808f..df1a03a5ad6 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestFilterDisplayModeScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestFilterDisplayModeScreenPresenter.java @@ -37,7 +37,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestInputModeScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestInputModeScreenPresenter.java index e7abefd854a..d243e214562 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestInputModeScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestInputModeScreenPresenter.java @@ -38,7 +38,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestMessageModeScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestMessageModeScreenPresenter.java index 4b4d10e8323..823b9b485d0 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestMessageModeScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestMessageModeScreenPresenter.java @@ -30,7 +30,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenModel.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenModel.java index 177d64002c7..c44d1e6b1f7 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenModel.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenModel.java @@ -42,7 +42,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenPresenter.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenPresenter.java index 6a780b5ff85..e633303a111 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenPresenter.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/screen/top/TestTopScreenPresenter.java @@ -40,7 +40,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @Category(SmallTests.class) @RunWith(MockitoJUnitRunner.class) diff --git a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java index eff83edfa6b..9ad5ab9e9d9 100644 --- a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java @@ -18,7 +18,10 @@ package org.apache.hadoop.hbase.http.lib; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -36,7 +39,6 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; @Category({ MiscTests.class, SmallTests.class }) public class TestStaticUserWebFilter { @@ -46,9 +48,8 @@ public class TestStaticUserWebFilter { HBaseClassTestRule.forClass(TestStaticUserWebFilter.class); private FilterConfig mockConfig(String username) { - FilterConfig mock = Mockito.mock(FilterConfig.class); - Mockito.doReturn(username).when(mock) - .getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER); + FilterConfig mock = mock(FilterConfig.class); + doReturn(username).when(mock).getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER); return mock; } @@ -65,7 +66,7 @@ public class TestStaticUserWebFilter { suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), chain); - Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito. anyObject()); + verify(chain).doFilter(wrapperArg.capture(), any()); HttpServletRequestWrapper wrapper = wrapperArg.getValue(); assertEquals("myuser", wrapper.getUserPrincipal().getName()); diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestGroupingTableMap.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestGroupingTableMap.java index 4ccaa43a665..2912fd4d025 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestGroupingTableMap.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestGroupingTableMap.java @@ -19,12 +19,12 @@ package org.apache.hadoop.hbase.mapred; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertNull; -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; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.IOException; @@ -57,7 +57,7 @@ public class TestGroupingTableMap { HBaseClassTestRule.forClass(TestGroupingTableMap.class); @Test - @SuppressWarnings({ "deprecation", "unchecked" }) + @SuppressWarnings("unchecked") public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception { GroupingTableMap gTableMap = null; try { @@ -82,14 +82,14 @@ public class TestGroupingTableMap { mock(OutputCollector.class); gTableMap.map(null, result, outputCollectorMock, reporter); verify(result).listCells(); - verifyZeroInteractions(outputCollectorMock); + verifyNoInteractions(outputCollectorMock); } finally { if (gTableMap != null) gTableMap.close(); } } @Test - @SuppressWarnings({ "deprecation", "unchecked" }) + @SuppressWarnings("unchecked") public void shouldCreateNewKeyAlthoughExtraKey() throws Exception { GroupingTableMap gTableMap = null; try { @@ -122,7 +122,6 @@ public class TestGroupingTableMap { } @Test - @SuppressWarnings({ "deprecation" }) public void shouldCreateNewKey() throws Exception { GroupingTableMap gTableMap = null; try { @@ -171,7 +170,6 @@ public class TestGroupingTableMap { } @Test - @SuppressWarnings({ "deprecation" }) public void shouldReturnNullFromCreateGroupKey() throws Exception { GroupingTableMap gTableMap = null; try { diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestRowCounter.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestRowCounter.java index dc55ff977dc..0f71055c6a7 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestRowCounter.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestRowCounter.java @@ -20,8 +20,8 @@ package org.apache.hadoop.hbase.mapred; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestTableInputFormat.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestTableInputFormat.java index 0ec4c2ffa28..d15d3a57464 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestTableInputFormat.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapred/TestTableInputFormat.java @@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.mapred; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -207,7 +207,7 @@ public class TestTableInputFormat { }; Table htable = spy(createTable(name)); - doAnswer(a).when(htable).getScanner((Scan) anyObject()); + doAnswer(a).when(htable).getScanner(any(Scan.class)); return htable; } @@ -240,7 +240,7 @@ public class TestTableInputFormat { }; Table htable = spy(createTable(name)); - doAnswer(a).when(htable).getScanner((Scan) anyObject()); + doAnswer(a).when(htable).getScanner(any(Scan.class)); return htable; } diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java index 86bf3220658..4d3149b9d8e 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportExport.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormat.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormat.java index ca0b9df79d3..c12a7e817bb 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormat.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableInputFormat.java @@ -20,8 +20,7 @@ package org.apache.hadoop.hbase.mapreduce; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.*; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -209,7 +208,7 @@ public class TestTableInputFormat { }; Table htable = spy(createTable(name)); - doAnswer(a).when(htable).getScanner((Scan) anyObject()); + doAnswer(a).when(htable).getScanner(any(Scan.class)); return htable; } @@ -242,7 +241,7 @@ public class TestTableInputFormat { }; Table htable = spy(createTable(name)); - doAnswer(a).when(htable).getScanner((Scan) anyObject()); + doAnswer(a).when(htable).getScanner(any(Scan.class)); return htable; } diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteHTableRetries.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteHTableRetries.java index 9e8c9c475d2..65c8a4f6c7f 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteHTableRetries.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteHTableRetries.java @@ -19,8 +19,8 @@ package org.apache.hadoop.hbase.rest.client; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java index 4ce5ca74eaa..93f3ba31b2c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -405,31 +405,31 @@ public class TestMetaTableAccessor { HBaseTestingUtil.countRows(table); ClientMetaTableAccessor.Visitor visitor = mock(ClientMetaTableAccessor.Visitor.class); - doReturn(true).when(visitor).visit((Result) anyObject()); + doReturn(true).when(visitor).visit(any()); // Scanning the entire table should give us three rows MetaTableAccessor.scanMetaForTableRegions(connection, visitor, tableName); - verify(visitor, times(3)).visit((Result) anyObject()); + verify(visitor, times(3)).visit(any()); // Scanning the table with a specified empty start row should also // give us three hbase:meta rows reset(visitor); - doReturn(true).when(visitor).visit((Result) anyObject()); + doReturn(true).when(visitor).visit(any()); MetaTableAccessor.scanMeta(connection, visitor, tableName, null, 1000); - verify(visitor, times(3)).visit((Result) anyObject()); + verify(visitor, times(3)).visit(any()); // Scanning the table starting in the middle should give us two rows: // region_a and region_b reset(visitor); - doReturn(true).when(visitor).visit((Result) anyObject()); + doReturn(true).when(visitor).visit(any()); MetaTableAccessor.scanMeta(connection, visitor, tableName, Bytes.toBytes("region_ac"), 1000); - verify(visitor, times(2)).visit((Result) anyObject()); + verify(visitor, times(2)).visit(any()); // Scanning with a limit of 1 should only give us one row reset(visitor); - doReturn(true).when(visitor).visit((Result) anyObject()); + doReturn(true).when(visitor).visit(any()); MetaTableAccessor.scanMeta(connection, visitor, tableName, Bytes.toBytes("region_ac"), 1); - verify(visitor, times(1)).visit((Result) anyObject()); + verify(visitor, times(1)).visit(any()); table.close(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/locking/TestEntityLocks.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/locking/TestEntityLocks.java index 614f68dcd60..d205b44f749 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/locking/TestEntityLocks.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/locking/TestEntityLocks.java @@ -20,9 +20,9 @@ package org.apache.hadoop.hbase.client.locking; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java index 775f1995280..750e63090cd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java @@ -18,6 +18,12 @@ package org.apache.hadoop.hbase.errorhandling; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MasterTests; @@ -25,7 +31,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,11 +52,11 @@ public class TestTimeoutExceptionInjector { @Test public void testTimerTrigger() { final long time = 10000000; // pick a value that is very far in the future - ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); + ForeignExceptionListener listener = mock(ForeignExceptionListener.class); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); timer.start(); timer.trigger(); - Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any()); + verify(listener, times(1)).receive(any()); } /** @@ -60,11 +65,11 @@ public class TestTimeoutExceptionInjector { @Test public void testTimerPassesOnErrorInfo() { final long time = 1000000; - ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); + ForeignExceptionListener listener = mock(ForeignExceptionListener.class); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); timer.start(); timer.trigger(); - Mockito.verify(listener).receive(Mockito.any()); + verify(listener).receive(any()); } /** @@ -74,7 +79,7 @@ public class TestTimeoutExceptionInjector { @Test public void testStartAfterComplete() throws InterruptedException { final long time = 10; - ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); + ForeignExceptionListener listener = mock(ForeignExceptionListener.class); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); timer.complete(); try { @@ -84,7 +89,7 @@ public class TestTimeoutExceptionInjector { LOG.debug("Correctly failed timer: " + e.getMessage()); } Thread.sleep(time + 1); - Mockito.verifyZeroInteractions(listener); + verifyNoInteractions(listener); } /** @@ -94,7 +99,7 @@ public class TestTimeoutExceptionInjector { @Test public void testStartAfterTrigger() throws InterruptedException { final long time = 10; - ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); + ForeignExceptionListener listener = mock(ForeignExceptionListener.class); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); timer.trigger(); try { @@ -104,7 +109,7 @@ public class TestTimeoutExceptionInjector { LOG.debug("Correctly failed timer: " + e.getMessage()); } Thread.sleep(time * 2); - Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any()); - Mockito.verifyNoMoreInteractions(listener); + verify(listener, times(1)).receive(any()); + verifyNoMoreInteractions(listener); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java index de992e9c6de..dfea5343073 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java @@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.executor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -205,7 +205,7 @@ public class TestExecutorService { @Override public boolean evaluate() throws Exception { try { - verify(server, times(1)).abort(anyString(), (Throwable) anyObject()); + verify(server, times(1)).abort(anyString(), any()); return true; } catch (Throwable t) { return false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedure.java index 8c08be7b7c9..96906701b0d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedure.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.procedure; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureCoordinator.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureCoordinator.java index d15a7cc244e..06dae4a32c8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureCoordinator.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureCoordinator.java @@ -19,10 +19,10 @@ package org.apache.hadoop.hbase.procedure; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; @@ -111,7 +111,7 @@ public class TestProcedureCoordinator { Procedure proc2 = new Procedure(coordinator, monitor, WAKE_FREQUENCY, TIMEOUT, procName + "2", procData, expected); Procedure procSpy2 = spy(proc2); - when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) + when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList())) .thenReturn(procSpy, procSpy2); coordinator.startProcedure(procSpy.getErrorMonitor(), procName, procData, expected); @@ -132,13 +132,12 @@ public class TestProcedureCoordinator { new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected); final Procedure procSpy = spy(proc); - when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) + when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList())) .thenReturn(procSpy); // use the passed controller responses IOException cause = new IOException("Failed to reach comms during acquire"); - doThrow(cause).when(controller).sendGlobalBarrierAcquire(eq(procSpy), eq(procData), - anyListOf(String.class)); + doThrow(cause).when(controller).sendGlobalBarrierAcquire(eq(procSpy), eq(procData), anyList()); // run the operation proc = coordinator.startProcedure(proc.getErrorMonitor(), procName, procData, expected); @@ -148,7 +147,7 @@ public class TestProcedureCoordinator { verify(procSpy, atLeastOnce()).receive(any()); verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause)); verify(controller, times(1)).sendGlobalBarrierAcquire(procSpy, procData, expected); - verify(controller, never()).sendGlobalBarrierReached(any(), anyListOf(String.class)); + verify(controller, never()).sendGlobalBarrierReached(any(), anyList()); } /** @@ -163,14 +162,13 @@ public class TestProcedureCoordinator { final Procedure spy = spy(new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected)); - when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) - .thenReturn(spy); + when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList())).thenReturn(spy); // use the passed controller responses IOException cause = new IOException("Failed to reach controller during prepare"); doAnswer(new AcquireBarrierAnswer(procName, new String[] { "cohort" })).when(controller) - .sendGlobalBarrierAcquire(eq(spy), eq(procData), anyListOf(String.class)); - doThrow(cause).when(controller).sendGlobalBarrierReached(eq(spy), anyListOf(String.class)); + .sendGlobalBarrierAcquire(eq(spy), eq(procData), anyList()); + doThrow(cause).when(controller).sendGlobalBarrierReached(eq(spy), anyList()); // run the operation Procedure task = @@ -180,9 +178,8 @@ public class TestProcedureCoordinator { ; verify(spy, atLeastOnce()).receive(any()); verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause)); - verify(controller, times(1)).sendGlobalBarrierAcquire(eq(spy), eq(procData), - anyListOf(String.class)); - verify(controller, times(1)).sendGlobalBarrierReached(any(), anyListOf(String.class)); + verify(controller, times(1)).sendGlobalBarrierAcquire(eq(spy), eq(procData), anyList()); + verify(controller, times(1)).sendGlobalBarrierReached(any(), anyList()); } @Test @@ -273,13 +270,11 @@ public class TestProcedureCoordinator { public void runCoordinatedOperation(Procedure spy, AcquireBarrierAnswer prepareOperation, BarrierAnswer commitOperation, String... cohort) throws Exception { List expected = Arrays.asList(cohort); - when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) - .thenReturn(spy); + when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList())).thenReturn(spy); // use the passed controller responses doAnswer(prepareOperation).when(controller).sendGlobalBarrierAcquire(spy, procData, expected); - doAnswer(commitOperation).when(controller).sendGlobalBarrierReached(eq(spy), - anyListOf(String.class)); + doAnswer(commitOperation).when(controller).sendGlobalBarrierReached(eq(spy), anyList()); // run the operation Procedure task = @@ -294,7 +289,7 @@ public class TestProcedureCoordinator { inorder.verify(spy).sendGlobalBarrierStart(); inorder.verify(controller).sendGlobalBarrierAcquire(task, procData, expected); inorder.verify(spy).sendGlobalBarrierReached(); - inorder.verify(controller).sendGlobalBarrierReached(eq(task), anyListOf(String.class)); + inorder.verify(controller).sendGlobalBarrierReached(eq(task), anyList()); } private static abstract class OperationAnswer implements Answer { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureMember.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureMember.java index 230f89e690c..2fc13877899 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureMember.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestProcedureMember.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.procedure; -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.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; @@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import java.io.IOException; @@ -420,7 +420,7 @@ public class TestProcedureMember { } // no request should reach the pool - verifyZeroInteractions(pool); + verifyNoInteractions(pool); // get two abort requests // TODO Need to do another refactor to get this to propagate to the coordinator. // verify(mockMemberComms, times(2)).sendMemberAborted(any(), any()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestZKProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestZKProcedure.java index e32459af5f7..a9fac158398 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestZKProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/TestZKProcedure.java @@ -19,9 +19,9 @@ package org.apache.hadoop.hbase.procedure; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -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.atMost; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -291,7 +291,7 @@ public class TestZKProcedure { Mockito.spy(new ForeignExceptionDispatcher()); Procedure coordinatorTask = Mockito.spy(new Procedure(coordinator, coordinatorTaskErrorMonitor, WAKE_FREQUENCY, TIMEOUT, opName, data, expected)); - when(coordinator.createProcedure(any(), eq(opName), eq(data), anyListOf(String.class))) + when(coordinator.createProcedure(any(), eq(opName), eq(data), anyList())) .thenReturn(coordinatorTask); // count down the error latch when we get the remote error Mockito.doAnswer(new Answer() { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestFileSystemUtilizationChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestFileSystemUtilizationChore.java index 3c7c4883bfa..529088c9c0c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestFileSystemUtilizationChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestFileSystemUtilizationChore.java @@ -19,8 +19,9 @@ package org.apache.hadoop.hbase.quotas; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -43,7 +44,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -68,7 +68,7 @@ public class TestFileSystemUtilizationChore { .reportRegionSizesForQuotas(any(RegionSizeStore.class)); final Region region = mockRegionWithSize(regionSizes); - Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions(); + doReturn(Arrays.asList(region)).when(rs).getRegions(); chore.chore(); } @@ -83,7 +83,7 @@ public class TestFileSystemUtilizationChore { .reportRegionSizesForQuotas(any(RegionSizeStore.class)); final Region region = mockRegionWithSize(regionSizes); - Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions(); + doReturn(Arrays.asList(region)).when(rs).getRegions(); chore.chore(); } @@ -107,7 +107,7 @@ public class TestFileSystemUtilizationChore { final Region r1 = mockRegionWithSize(r1Sizes); final Region r2 = mockRegionWithSize(r2Sizes); final Region r3 = mockRegionWithSize(r3Sizes); - Mockito.doReturn(Arrays.asList(r1, r2, r3)).when(rs).getRegions(); + doReturn(Arrays.asList(r1, r2, r3)).when(rs).getRegions(); chore.chore(); } @@ -169,7 +169,7 @@ public class TestFileSystemUtilizationChore { final Region r1 = mockRegionWithSize(Arrays.asList(1024L, 2048L)); final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L)); final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L)); - Mockito.doReturn(Arrays.asList(r1, r2, r3, lr1, lr2)).when(rs).getRegions(); + doReturn(Arrays.asList(r1, r2, r3, lr1, lr2)).when(rs).getRegions(); chore.chore(); } @@ -200,7 +200,7 @@ public class TestFileSystemUtilizationChore { final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L)); final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L)); // lr2 is no longer online, so it should be ignored - Mockito.doReturn(Arrays.asList(r1, r2, r3, lr1)).when(rs).getRegions(); + doReturn(Arrays.asList(r1, r2, r3, lr1)).when(rs).getRegions(); chore.chore(); } @@ -221,7 +221,7 @@ public class TestFileSystemUtilizationChore { final Region r1 = mockRegionWithSize(r1Sizes); final Region r2 = mockSplitParentRegionWithSize(r2Sizes); - Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); + doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); chore.chore(); } @@ -241,7 +241,7 @@ public class TestFileSystemUtilizationChore { final Region r1 = mockRegionWithSize(r1Sizes); final Region r2 = mockRegionReplicaWithSize(r2Sizes); - Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); + doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); chore.chore(); } @@ -267,7 +267,7 @@ public class TestFileSystemUtilizationChore { final Region r1 = mockRegionWithHFileLinks(r1StoreFileSizes, r1HFileSizes); final Region r2 = mockRegionWithHFileLinks(r2StoreFileSizes, r2HFileSizes); - Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); + doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); chore.chore(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserverWithMocks.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserverWithMocks.java index aa7edca9959..1852ccc3347 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserverWithMocks.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserverWithMocks.java @@ -22,7 +22,7 @@ import static org.apache.hadoop.hbase.quotas.MasterQuotasObserver.REMOVE_QUOTA_O import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestNamespaceQuotaViolationStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestNamespaceQuotaViolationStore.java index 11c2188dbbc..70f2d55bba7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestNamespaceQuotaViolationStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestNamespaceQuotaViolationStore.java @@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.quotas; import static org.apache.hbase.thirdparty.com.google.common.collect.Iterables.size; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java index 29f33e22509..a827470a00b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java @@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.quotas; import static org.apache.hadoop.hbase.util.Bytes.toBytes; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -68,7 +68,6 @@ public class TestSpaceQuotaViolationPolicyRefresherChore { private Configuration conf; private Connection conn; - @SuppressWarnings("unchecked") @Before public void setup() throws IOException { conf = HBaseConfiguration.create(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableQuotaViolationStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableQuotaViolationStore.java index 7ff01a1cc4e..ca34410bdad 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableQuotaViolationStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableQuotaViolationStore.java @@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.quotas; import static org.apache.hbase.thirdparty.com.google.common.collect.Iterables.size; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableSpaceQuotaViolationNotifier.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableSpaceQuotaViolationNotifier.java index 75170461b1c..d7de58786ad 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableSpaceQuotaViolationNotifier.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestTableSpaceQuotaViolationNotifier.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.quotas; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/StatefulStoreMockMaker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/StatefulStoreMockMaker.java index 89439a546bf..bae811bd519 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/StatefulStoreMockMaker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/StatefulStoreMockMaker.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java index 699d4abb345..476e3bd330b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java @@ -19,7 +19,11 @@ package org.apache.hadoop.hbase.regionserver; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.IOException; @@ -53,7 +57,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.TestName; -import org.mockito.Mockito; import org.mockito.exceptions.verification.WantedButNotInvoked; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -249,8 +252,7 @@ public class TestFailedAppendAndSync { // to just continue. // So, should be no abort at this stage. Verify. - Mockito.verify(services, Mockito.atLeast(0)).abort(Mockito.anyString(), - Mockito.any(Throwable.class)); + verify(services, atLeast(0)).abort(anyString(), any(Throwable.class)); try { dodgyWAL.throwAppendException = false; dodgyWAL.throwSyncException = true; @@ -265,8 +267,7 @@ public class TestFailedAppendAndSync { // happens. If it don't we'll timeout the whole test. That is fine. while (true) { try { - Mockito.verify(services, Mockito.atLeast(1)).abort(Mockito.anyString(), - Mockito.any(Throwable.class)); + verify(services, atLeast(1)).abort(anyString(), any(Throwable.class)); break; } catch (WantedButNotInvoked t) { Threads.sleep(1); @@ -286,8 +287,7 @@ public class TestFailedAppendAndSync { while (true) { try { // one more abort needs to be called - Mockito.verify(services, Mockito.atLeast(2)).abort(Mockito.anyString(), - (Throwable) Mockito.anyObject()); + verify(services, atLeast(2)).abort(anyString(), any()); break; } catch (WantedButNotInvoked t) { Threads.sleep(1); @@ -295,7 +295,7 @@ public class TestFailedAppendAndSync { } } finally { // To stop logRoller, its server has to say it is stopped. - Mockito.when(services.isStopped()).thenReturn(true); + when(services.isStopped()).thenReturn(true); if (logRoller != null) logRoller.close(); if (region != null) { try { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index 3ac6faf2df8..637aab9ff5c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -32,7 +32,9 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -182,7 +184,6 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TestName; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; -import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.slf4j.Logger; @@ -415,9 +416,8 @@ public class TestHRegion { long onePutSize = region.getMemStoreDataSize(); assertTrue(onePutSize > 0); - RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class); - doThrow(new IOException()).when(mockedCPHost) - .postBatchMutate(Mockito.> any()); + RegionCoprocessorHost mockedCPHost = mock(RegionCoprocessorHost.class); + doThrow(new IOException()).when(mockedCPHost).postBatchMutate(any()); region.setCoprocessorHost(mockedCPHost); put = new Put(value); @@ -3387,25 +3387,24 @@ public class TestHRegion { final long initSize = region.getDataInMemoryWithoutWAL(); // save normalCPHost and replaced by mockedCPHost RegionCoprocessorHost normalCPHost = region.getCoprocessorHost(); - RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class); + RegionCoprocessorHost mockedCPHost = mock(RegionCoprocessorHost.class); // Because the preBatchMutate returns void, we can't do usual Mockito when...then form. Must // do below format (from Mockito doc). - Mockito.doAnswer(new Answer() { + doAnswer(new Answer() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { MiniBatchOperationInProgress mb = invocation.getArgument(0); mb.addOperationsFromCP(0, new Mutation[] { addPut }); return null; } - }).when(mockedCPHost).preBatchMutate(Mockito.isA(MiniBatchOperationInProgress.class)); + }).when(mockedCPHost).preBatchMutate(isA(MiniBatchOperationInProgress.class)); ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder.newBuilder(COLUMN_FAMILY_BYTES); ScanInfo info = new ScanInfo(CONF, builder.build(), Long.MAX_VALUE, Long.MAX_VALUE, region.getCellComparator()); - Mockito.when(mockedCPHost.preFlushScannerOpen(Mockito.any(HStore.class), Mockito.any())) - .thenReturn(info); - Mockito - .when(mockedCPHost.preFlush(Mockito.any(), Mockito.any(StoreScanner.class), Mockito.any())) + when(mockedCPHost.preFlushScannerOpen(any(HStore.class), any())).thenReturn(info); + + when(mockedCPHost.preFlush(any(), any(StoreScanner.class), any())) .thenAnswer(i -> i.getArgument(1)); region.setCoprocessorHost(mockedCPHost); @@ -5106,8 +5105,8 @@ public class TestHRegion { public void testStatusSettingToAbortIfAnyExceptionDuringRegionInitilization() throws Exception { RegionInfo info; try { - FileSystem fs = Mockito.mock(FileSystem.class); - Mockito.when(fs.exists((Path) Mockito.anyObject())).thenThrow(new IOException()); + FileSystem fs = mock(FileSystem.class); + when(fs.exists(any())).thenThrow(new IOException()); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")).build(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java index 6459a9927eb..2ce0f0fa61e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java @@ -20,8 +20,8 @@ package org.apache.hadoop.hbase.regionserver; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitWalDataLoss.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitWalDataLoss.java index 3fe5ad9faf3..17754d498e0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitWalDataLoss.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitWalDataLoss.java @@ -19,11 +19,11 @@ package org.apache.hadoop.hbase.regionserver; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.spy; import java.io.IOException; -import java.util.Collection; import java.util.Map; import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.hadoop.hbase.DroppedSnapshotException; @@ -40,19 +40,15 @@ import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; -import org.apache.hadoop.hbase.monitoring.MonitoredTask; import org.apache.hadoop.hbase.regionserver.HRegion.FlushResult; -import org.apache.hadoop.hbase.regionserver.HRegion.PrepareFlushResult; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.apache.hadoop.hbase.wal.WAL; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.mockito.Matchers; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.slf4j.Logger; @@ -120,9 +116,7 @@ public class TestSplitWalDataLoss { .abortCacheFlush(region.getRegionInfo().getEncodedNameAsBytes()); throw new DroppedSnapshotException("testcase"); } - }).when(spiedRegion).internalFlushCacheAndCommit(Matchers. any(), - Matchers. any(), Matchers. any(), - Matchers.> any()); + }).when(spiedRegion).internalFlushCacheAndCommit(any(), any(), any(), any()); // Find region key; don't pick up key for hbase:meta by mistake. String key = null; for (Map.Entry entry : rs.getOnlineRegions().entrySet()) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCompactor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCompactor.java index 9c03f368cb8..5359dec2e64 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCompactor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCompactor.java @@ -25,10 +25,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyCollection; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/compaction/TestMajorCompactionRequest.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/compaction/TestMajorCompactionRequest.java index 66541e801f8..8c4b6ebaf13 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/compaction/TestMajorCompactionRequest.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/compaction/TestMajorCompactionRequest.java @@ -21,8 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/pom.xml b/pom.xml index 91d8584cd5f..c6ad9d51a81 100644 --- a/pom.xml +++ b/pom.xml @@ -824,7 +824,7 @@ 1.15.0 1.15.0 2.17.2 - 2.28.2 + 4.11.0 0.6.1 thrift 0.14.1 @@ -1545,9 +1545,10 @@ org.mockito - mockito-core - ${mockito-core.version} - test + mockito-bom + ${mockito.version} + pom + import io.opentelemetry