You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by xv...@apache.org on 2022/03/19 17:19:08 UTC
[druid] branch master updated: fix use of deprecated initMocks method (#12351)
This is an automated email from the ASF dual-hosted git repository.
xvrl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 1f0447e fix use of deprecated initMocks method (#12351)
1f0447e is described below
commit 1f0447e613906425d863b8d7a2152cc41fedbf0e
Author: Xavier Léauté <xv...@apache.org>
AuthorDate: Sat Mar 19 10:19:02 2022 -0700
fix use of deprecated initMocks method (#12351)
follow-up to #12341
- fix use of deprecated initMocks methods and properly close mocks on teardown
---
.../join/table/IndexedTableJoinMatcherTest.java | 165 ++++++++++++---------
1 file changed, 92 insertions(+), 73 deletions(-)
diff --git a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
index 6d6e930..bf37903 100644
--- a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
+++ b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java
@@ -35,6 +35,7 @@ import org.apache.druid.segment.DimensionSelector;
import org.apache.druid.segment.column.ColumnType;
import org.apache.druid.segment.data.ArrayBasedIndexedInts;
import org.apache.druid.testing.InitializedNullHandlingTest;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -60,16 +61,14 @@ public class IndexedTableJoinMatcherTest
{
public static class MakeLongProcessorTest extends InitializedNullHandlingTest
{
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Mock
private BaseLongColumnValueSelector selector;
+ private AutoCloseable mocks;
@Before
public void setUp()
{
- MockitoAnnotations.initMocks(this);
+ mocks = MockitoAnnotations.openMocks(this);
if (NullHandling.sqlCompatible()) {
Mockito.doReturn(false).when(selector).isNull();
@@ -78,6 +77,12 @@ public class IndexedTableJoinMatcherTest
Mockito.doReturn(1L).when(selector).getLong();
}
+ @After
+ public void tearDown() throws Exception
+ {
+ mocks.close();
+ }
+
@Test
public void testMatchToUniqueLongIndex()
{
@@ -115,8 +120,7 @@ public class IndexedTableJoinMatcherTest
new IndexedTableJoinMatcher.ConditionMatcherFactory(longAlwaysOneTwoThreeIndex());
final IndexedTableJoinMatcher.ConditionMatcher processor = conditionMatcherFactory.makeLongProcessor(selector);
- expectedException.expect(UnsupportedOperationException.class);
- processor.matchSingleRow();
+ Assert.assertThrows(UnsupportedOperationException.class, processor::matchSingleRow);
}
@Test
@@ -147,11 +151,18 @@ public class IndexedTableJoinMatcherTest
@Mock
private BaseObjectColumnValueSelector<?> selector;
+ private AutoCloseable mocks;
@Before
public void setUp()
{
- MockitoAnnotations.initMocks(this);
+ mocks = MockitoAnnotations.openMocks(this);
+ }
+
+ @After
+ public void tearDown() throws Exception
+ {
+ mocks.close();
}
@Test
@@ -190,85 +201,93 @@ public class IndexedTableJoinMatcherTest
private static final String KEY = "key";
@Test
- public void testMatchMultiValuedRowCardinalityUnknownShouldThrowException()
- {
- MockitoAnnotations.initMocks(this);
- ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{2, 4, 6});
- Mockito.doReturn(row).when(dimensionSelector).getRow();
- Mockito.doReturn(DimensionDictionarySelector.CARDINALITY_UNKNOWN).when(dimensionSelector).getValueCardinality();
-
- IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
- new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
- IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
- dimensionSelector,
- false
- );
-
- // Test match should throw exception
- expectedException.expect(QueryUnsupportedException.class);
- dimensionProcessor.match();
+ public void testMatchMultiValuedRowCardinalityUnknownShouldThrowException() throws Exception
+ {
+ try (final AutoCloseable mocks = MockitoAnnotations.openMocks(this)) {
+ ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{2, 4, 6});
+ Mockito.doReturn(row).when(dimensionSelector).getRow();
+ Mockito.doReturn(DimensionDictionarySelector.CARDINALITY_UNKNOWN)
+ .when(dimensionSelector)
+ .getValueCardinality();
+
+ IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
+ new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
+ IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
+ dimensionSelector,
+ false
+ );
+
+ // Test match should throw exception
+ expectedException.expect(QueryUnsupportedException.class);
+ dimensionProcessor.match();
+ }
}
@Test
- public void testMatchMultiValuedRowCardinalityKnownShouldThrowException()
- {
- MockitoAnnotations.initMocks(this);
- ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{2, 4, 6});
- Mockito.doReturn(row).when(dimensionSelector).getRow();
- Mockito.doReturn(3).when(dimensionSelector).getValueCardinality();
-
- IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
- new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
- IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
- dimensionSelector,
- false
- );
-
- // Test match should throw exception
- expectedException.expect(QueryUnsupportedException.class);
- dimensionProcessor.match();
+ public void testMatchMultiValuedRowCardinalityKnownShouldThrowException() throws Exception
+ {
+ try (final AutoCloseable mocks = MockitoAnnotations.openMocks(this)) {
+ ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{2, 4, 6});
+ Mockito.doReturn(row).when(dimensionSelector).getRow();
+ Mockito.doReturn(3).when(dimensionSelector).getValueCardinality();
+
+ IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
+ new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
+ IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
+ dimensionSelector,
+ false
+ );
+
+ // Test match should throw exception
+ expectedException.expect(QueryUnsupportedException.class);
+ dimensionProcessor.match();
+ }
}
@Test
- public void testMatchEmptyRowCardinalityUnknown()
- {
- MockitoAnnotations.initMocks(this);
- ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{});
- Mockito.doReturn(row).when(dimensionSelector).getRow();
- Mockito.doReturn(DimensionDictionarySelector.CARDINALITY_UNKNOWN).when(dimensionSelector).getValueCardinality();
-
- IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
- new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
- IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
- dimensionSelector,
- false
- );
-
- Assert.assertNotNull(dimensionProcessor.match());
- Assert.assertFalse(dimensionProcessor.match().hasNext());
-
- Assert.assertEquals(IndexedTableJoinMatcher.NO_CONDITION_MATCH, dimensionProcessor.matchSingleRow());
+ public void testMatchEmptyRowCardinalityUnknown() throws Exception
+ {
+ try (final AutoCloseable mocks = MockitoAnnotations.openMocks(this)) {
+ ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{});
+ Mockito.doReturn(row).when(dimensionSelector).getRow();
+ Mockito.doReturn(DimensionDictionarySelector.CARDINALITY_UNKNOWN)
+ .when(dimensionSelector)
+ .getValueCardinality();
+
+ IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
+ new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
+ IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
+ dimensionSelector,
+ false
+ );
+
+ Assert.assertNotNull(dimensionProcessor.match());
+ Assert.assertFalse(dimensionProcessor.match().hasNext());
+
+ Assert.assertEquals(IndexedTableJoinMatcher.NO_CONDITION_MATCH, dimensionProcessor.matchSingleRow());
+ }
}
@Test
- public void testMatchEmptyRowCardinalityKnown()
+ public void testMatchEmptyRowCardinalityKnown() throws Exception
{
- MockitoAnnotations.initMocks(this);
- ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{});
- Mockito.doReturn(row).when(dimensionSelector).getRow();
- Mockito.doReturn(0).when(dimensionSelector).getValueCardinality();
+ try (final AutoCloseable mocks = MockitoAnnotations.openMocks(this)) {
+ ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[]{});
+ Mockito.doReturn(row).when(dimensionSelector).getRow();
+ Mockito.doReturn(0).when(dimensionSelector).getValueCardinality();
- IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
- new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
- IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
- dimensionSelector,
- false
- );
+ IndexedTableJoinMatcher.ConditionMatcherFactory conditionMatcherFactory =
+ new IndexedTableJoinMatcher.ConditionMatcherFactory(stringToLengthIndex());
+ IndexedTableJoinMatcher.ConditionMatcher dimensionProcessor = conditionMatcherFactory.makeDimensionProcessor(
+ dimensionSelector,
+ false
+ );
- Assert.assertNotNull(dimensionProcessor.match());
- Assert.assertFalse(dimensionProcessor.match().hasNext());
+ Assert.assertNotNull(dimensionProcessor.match());
+ Assert.assertFalse(dimensionProcessor.match().hasNext());
- Assert.assertEquals(IndexedTableJoinMatcher.NO_CONDITION_MATCH, dimensionProcessor.matchSingleRow());
+ Assert.assertEquals(IndexedTableJoinMatcher.NO_CONDITION_MATCH, dimensionProcessor.matchSingleRow());
+ }
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org