diff --git a/parquet-avro/pom.xml b/parquet-avro/pom.xml index 68815da263..28c9658317 100644 --- a/parquet-avro/pom.xml +++ b/parquet-avro/pom.xml @@ -112,25 +112,7 @@ org.mockito mockito-core - 2.23.0 - test - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-core - ${powermock.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.version} + ${mockito.version} test diff --git a/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroRecordConverter.java b/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroRecordConverter.java index 315320bbdc..7c1db48f46 100644 --- a/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroRecordConverter.java +++ b/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroRecordConverter.java @@ -34,22 +34,25 @@ import org.apache.avro.Schema; import org.apache.avro.SchemaBuilder; import org.apache.avro.specific.SpecificData; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; +import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest(AvroRecordConverter.class) public class TestAvroRecordConverter { + private MockedStatic avroRecordConverterMock; + @Before public void setup() { // Default to calling real methods unless overridden in specific test - PowerMockito.mockStatic(AvroRecordConverter.class, CALLS_REAL_METHODS); + avroRecordConverterMock = Mockito.mockStatic(AvroRecordConverter.class, CALLS_REAL_METHODS); + } + + @After + public void tearDown() { + avroRecordConverterMock.close(); } @Test @@ -86,7 +89,7 @@ public void testModelForGenericRecord() { // Test logical type support for older Avro versions @Test public void testModelForSpecificRecordWithLogicalTypesWithDeprecatedAvro1_8() { - Mockito.when(AvroRecordConverter.getRuntimeAvroVersion()).thenReturn("1.8.2"); + avroRecordConverterMock.when(AvroRecordConverter::getRuntimeAvroVersion).thenReturn("1.8.2"); // Test that model is generated correctly when record contains both top-level and nested logical types SpecificData model = AvroRecordConverter.getModelForSchema(LogicalTypesTestDeprecated.SCHEMA$); @@ -108,7 +111,7 @@ public void testModelForSpecificRecordWithLogicalTypesWithDeprecatedAvro1_8() { @Test public void testModelForSpecificRecordWithLogicalTypesWithDeprecatedAvro1_7() { - Mockito.when(AvroRecordConverter.getRuntimeAvroVersion()).thenReturn("1.7.7"); + avroRecordConverterMock.when(AvroRecordConverter::getRuntimeAvroVersion).thenReturn("1.7.7"); // Test that model is generated correctly final SpecificData model = AvroRecordConverter.getModelForSchema(LogicalTypesTestDeprecated.SCHEMA$); diff --git a/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroSchemaConverter.java b/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroSchemaConverter.java index 346fafe7d3..3a78eefbb0 100644 --- a/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroSchemaConverter.java +++ b/parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroSchemaConverter.java @@ -62,25 +62,27 @@ import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName; import org.apache.parquet.schema.Type; import org.apache.parquet.schema.Types; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; +import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest(AvroRecordConverter.class) public class TestAvroSchemaConverter { private static final Configuration NEW_BEHAVIOR = new Configuration(false); + private MockedStatic avroRecordConverterMock; @Before public void setupMockito() { - PowerMockito.mockStatic(AvroRecordConverter.class, CALLS_REAL_METHODS); + avroRecordConverterMock = Mockito.mockStatic(AvroRecordConverter.class, CALLS_REAL_METHODS); + } + + @After + public void tearDown() { + avroRecordConverterMock.close(); } @BeforeClass @@ -706,7 +708,9 @@ public void testTimestampMillisType() throws Exception { // Test that conversions for timestamp types only use APIs that are available in the user's Avro version for (String avroVersion : ImmutableSet.of("1.7.0", "1.8.0", "1.9.0", "1.10.0", "1.11.0")) { - Mockito.when(AvroRecordConverter.getRuntimeAvroVersion()).thenReturn(avroVersion); + avroRecordConverterMock + .when(AvroRecordConverter::getRuntimeAvroVersion) + .thenReturn(avroVersion); final Schema converted = new AvroSchemaConverter() .convert(Types.buildMessage() .addField(Types.primitive(INT64, Type.Repetition.REQUIRED) @@ -792,7 +796,9 @@ public void testTimestampMicrosType() throws Exception { // Test that conversions for timestamp types only use APIs that are available in the user's Avro version for (String avroVersion : ImmutableSet.of("1.7.0", "1.8.0", "1.9.0", "1.10.0", "1.11.0")) { - Mockito.when(AvroRecordConverter.getRuntimeAvroVersion()).thenReturn(avroVersion); + avroRecordConverterMock + .when(AvroRecordConverter::getRuntimeAvroVersion) + .thenReturn(avroVersion); final Schema converted = new AvroSchemaConverter() .convert(Types.buildMessage() .addField(Types.primitive(INT64, Type.Repetition.REQUIRED) diff --git a/parquet-column/pom.xml b/parquet-column/pom.xml index 8bd11dcc26..1f6ba6f510 100644 --- a/parquet-column/pom.xml +++ b/parquet-column/pom.xml @@ -90,7 +90,7 @@ org.mockito - mockito-all + mockito-core ${mockito.version} test @@ -100,6 +100,12 @@ ${commons-lang3.version} test + + org.hamcrest + hamcrest-core + 1.3 + test + diff --git a/parquet-common/pom.xml b/parquet-common/pom.xml index 08a3b1188b..ef96c5c00a 100644 --- a/parquet-common/pom.xml +++ b/parquet-common/pom.xml @@ -64,7 +64,7 @@ org.mockito - mockito-all + mockito-core ${mockito.version} test diff --git a/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java b/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java index 6ffe3c650a..38d4b79219 100644 --- a/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java +++ b/parquet-common/src/test/java/org/apache/parquet/bytes/TestBytesInput.java @@ -21,8 +21,8 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -401,6 +401,6 @@ private void validateToByteBufferIsInternal(Supplier factory) { Consumer callbackMock = Mockito.mock(Consumer.class); factory.get().toByteBuffer(allocatorMock, callbackMock); verify(allocatorMock, never()).allocate(anyInt()); - verify(callbackMock, never()).accept(anyObject()); + verify(callbackMock, never()).accept(any()); } } diff --git a/parquet-hadoop/pom.xml b/parquet-hadoop/pom.xml index 5d133a2be4..4d13d9eebb 100644 --- a/parquet-hadoop/pom.xml +++ b/parquet-hadoop/pom.xml @@ -170,7 +170,7 @@ org.mockito - mockito-all + mockito-core ${mockito.version} test @@ -191,6 +191,12 @@ slf4j-api ${slf4j.version} + + org.hamcrest + hamcrest-core + 1.3 + test + commons-io commons-io diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java index f5f414c864..21b0ca3b70 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/filter2/dictionarylevel/DictionaryFilterTest.java @@ -45,7 +45,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -732,7 +732,7 @@ public void testColumnWithoutDictionary() throws Exception { "Should never drop block using plain encoding", canDrop(notEq(plain, nElements + 10), ccmd, dictionaryStore)); - verifyZeroInteractions(dictionaryStore); + verifyNoInteractions(dictionaryStore); } @Test @@ -758,7 +758,7 @@ public void testColumnWithDictionaryAndPlainEncodings() throws Exception { "Should never drop block using plain encoding", canDrop(notEq(plain, nElements + 10), ccmd, dictionaryStore)); - verifyZeroInteractions(dictionaryStore); + verifyNoInteractions(dictionaryStore); } @Test diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java index 2b037b5261..a17cf678f5 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestColumnChunkPageWriteStore.java @@ -32,10 +32,10 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; -import static org.mockito.Matchers.same; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.inOrder; import java.io.ByteArrayInputStream; diff --git a/parquet-thrift/pom.xml b/parquet-thrift/pom.xml index ade1ec3cdc..643d05375c 100644 --- a/parquet-thrift/pom.xml +++ b/parquet-thrift/pom.xml @@ -77,6 +77,12 @@ ${guava.version} test + + org.mockito + mockito-core + ${mockito.version} + test + com.twitter.elephantbird elephant-bird-core diff --git a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java index cee9e9bbd7..4f702b8919 100644 --- a/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java +++ b/parquet-thrift/src/test/java/org/apache/parquet/thrift/projection/TestStrictFieldProjectionFilter.java @@ -18,11 +18,12 @@ */ package org.apache.parquet.thrift.projection; -import static org.easymock.EasyMock.createMockBuilder; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import java.util.Arrays; import java.util.List; @@ -112,23 +113,18 @@ public void testIsStrict() { @Test public void testWarnWhenMultiplePatternsMatch() { - StrictFieldProjectionFilter filter = createMockBuilder(StrictFieldProjectionFilter.class) - .withConstructor(Arrays.asList("a.b.c.{x_average,z_average}", "a.*_average")) - .addMockedMethod("warn") - .createMock(); + StrictFieldProjectionFilter filter = spy(new StrictFieldProjectionFilter( + Arrays.asList("a.b.c.{x_average,z_average}", "a.*_average"))); + doNothing().when(filter).warn(anyString()); - // set expectations - filter.warn("Field path: 'a.b.c.x_average' matched more than one glob path pattern. " + assertMatches(filter, "a.b.c.x_average", "a.b.c.z_average", "a.other.w_average"); + assertDoesNotMatch(filter, "hello"); + + verify(filter).warn("Field path: 'a.b.c.x_average' matched more than one glob path pattern. " + "First match: 'a.b.c.{x_average,z_average}' (when expanded to 'a.b.c.x_average') " + "second match:'a.*_average' (when expanded to 'a.*_average')"); - filter.warn("Field path: 'a.b.c.z_average' matched more than one glob path pattern. " + verify(filter).warn("Field path: 'a.b.c.z_average' matched more than one glob path pattern. " + "First match: 'a.b.c.{x_average,z_average}' (when expanded to 'a.b.c.z_average') " + "second match:'a.*_average' (when expanded to 'a.*_average')"); - - replay(filter); - - assertMatches(filter, "a.b.c.x_average", "a.b.c.z_average", "a.other.w_average"); - assertDoesNotMatch(filter, "hello"); - verify(filter); } } diff --git a/pom.xml b/pom.xml index a4c3701df9..b761e7efeb 100644 --- a/pom.xml +++ b/pom.xml @@ -98,8 +98,7 @@ 1.11.5 33.5.0-jre 0.1.1 - 1.10.19 - 2.0.9 + 5.21.0 0.27ea0 3.5.0 1.20.0 @@ -163,12 +162,6 @@ 4.13.2 test - - org.easymock - easymock - 5.6.0 - test -