Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codestyle/druid-forbidden-apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ javax.annotation.concurrent.GuardedBy
com.amazonaws.annotation.GuardedBy

org.powermock.** @ Use Mockito instead of Powermock for compatibility with newer Java versions

org.junit.Assert#assertThat(java.lang.Object,org.hamcrest.Matcher) @ Use org.hamcrest.MatcherAssert#assertThat instead
org.junit.Assert#assertThat(java.lang.String,java.lang.Object,org.hamcrest.Matcher) @ Use org.hamcrest.MatcherAssert#assertThat instead
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.druid.query.aggregation.AggregationTestHelper;
import org.apache.druid.query.groupby.GroupByQueryConfig;
import org.apache.druid.query.groupby.ResultRow;
import org.hamcrest.MatcherAssert;
import org.hamcrest.collection.IsCollectionWithSize;
import org.hamcrest.collection.IsMapContaining;
import org.hamcrest.collection.IsMapWithSize;
Expand Down Expand Up @@ -107,32 +108,32 @@ public void testIngestAndGroupByAllQuery() throws IOException, Exception
);

List<ResultRow> results = seq.toList();
Assert.assertThat(results, IsCollectionWithSize.hasSize(1));
MatcherAssert.assertThat(results, IsCollectionWithSize.hasSize(1));
ResultRow row = results.get(0);
MapBasedRow mapBasedRow = row.toMapBasedRow(cbdGroupByQueryConfig.getQuery());
Map<String, Object> event = mapBasedRow.getEvent();
Assert.assertEquals(
new DateTime("2017-01-01T00:00:00Z", DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))),
mapBasedRow.getTimestamp()
);
Assert.assertThat(event, IsMapWithSize.aMapWithSize(3));
Assert.assertThat(
MatcherAssert.assertThat(event, IsMapWithSize.aMapWithSize(3));
MatcherAssert.assertThat(
event,
IsMapContaining.hasEntry(
"cbdRevenueFromString",
new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getStringRevenue()))
)
);
// long conversion of 5000000000.000000005 results in null/0 value
Assert.assertThat(
MatcherAssert.assertThat(
event,
IsMapContaining.hasEntry(
"cbdRevenueFromLong",
new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getLongRevenue()))
)
);
// double input changes 5000000000.000000005 to 5000000000.5 to fit in double mantissa space
Assert.assertThat(
MatcherAssert.assertThat(
event,
IsMapContaining.hasEntry(
"cbdRevenueFromDouble",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
import java.util.Map;
import java.util.TimeZone;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsMapContaining.hasEntry;
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public abstract class CompressedBigDecimalAggregatorTimeseriesTestBase extends InitializedNullHandlingTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.druid.query.movingaverage.averagers.LongMeanAveragerFactory;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.joda.time.DateTime;
import org.joda.time.chrono.ISOChronology;
import org.junit.Assert;
Expand Down Expand Up @@ -144,7 +145,7 @@ public void testNext()
r = iter.next();
Assert.assertEquals(JAN_3, r.getTimestamp());
Assert.assertEquals("US", r.getRaw(COUNTRY));
Assert.assertThat(r.getRaw(AGE), CoreMatchers.not(CoreMatchers.equalTo(r2.getRaw(AGE))));
MatcherAssert.assertThat(r.getRaw(AGE), CoreMatchers.not(CoreMatchers.equalTo(r2.getRaw(AGE))));

Assert.assertTrue(iter.hasNext());
r = iter.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.apache.druid.timeline.TimelineLookup;
import org.apache.druid.utils.JvmUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.joda.time.Interval;
import org.junit.Assert;
Expand Down Expand Up @@ -303,11 +304,11 @@ private List<MapBasedRow> consistentTypeCasting(List<MapBasedRow> result)
public void testQuery() throws IOException
{
Query<?> query = jsonMapper.readValue(getQueryString(), Query.class);
Assert.assertThat(query, IsInstanceOf.instanceOf(getExpectedQueryType()));
MatcherAssert.assertThat(query, IsInstanceOf.instanceOf(getExpectedQueryType()));

List<MapBasedRow> expectedResults = jsonMapper.readValue(getExpectedResultString(), getExpectedResultType());
Assert.assertNotNull(expectedResults);
Assert.assertThat(expectedResults, IsInstanceOf.instanceOf(List.class));
MatcherAssert.assertThat(expectedResults, IsInstanceOf.instanceOf(List.class));

DruidHttpClientConfig httpClientConfig = new DruidHttpClientConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.hamcrest.MatcherAssert;
import org.junit.Test;

public class DoubleMaxAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class DoubleMaxAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new DoubleMaxAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), CoreMatchers.instanceOf(DoubleMaxAverager.class));
MatcherAssert.assertThat(fac.createAverager(), CoreMatchers.instanceOf(DoubleMaxAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class DoubleMeanAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class DoubleMeanAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new DoubleMeanAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleMeanAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleMeanAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class DoubleMeanNoNullAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class DoubleMeanNoNullAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new DoubleMeanNoNullAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleMeanNoNullAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleMeanNoNullAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class DoubleMinAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class DoubleMinAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new DoubleMinAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleMinAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleMinAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class DoubleSumAveragerFactoryTest
Expand All @@ -30,7 +30,7 @@ public class DoubleSumAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new DoubleSumAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleSumAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(DoubleSumAverager.class));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class LongMaxAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class LongMaxAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new LongMaxAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMaxAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMaxAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class LongMeanAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class LongMeanAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new LongMeanAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMeanAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMeanAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class LongMeanNoNullAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class LongMeanNoNullAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new LongMeanNoNullAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMeanNoNullAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMeanNoNullAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class LongMinAveragerFactoryTest
Expand All @@ -29,6 +29,6 @@ public class LongMinAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new LongMinAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMinAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongMinAverager.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.druid.query.movingaverage.averagers;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Assert;
import org.junit.Test;

public class LongSumAveragerFactoryTest
Expand All @@ -30,7 +30,7 @@ public class LongSumAveragerFactoryTest
public void testCreateAverager()
{
AveragerFactory<?, ?> fac = new LongSumAveragerFactory("test", 5, 1, "field");
Assert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongSumAverager.class));
MatcherAssert.assertThat(fac.createAverager(), IsInstanceOf.instanceOf(LongSumAverager.class));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.druid.segment.vector.VectorCursor;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -168,7 +169,7 @@ public void testMultiString()
public void testComplexSketch()
{
final Object sketch = Iterables.getOnlyElement(readColumn("quality_uniques", 1));
Assert.assertThat(sketch, CoreMatchers.instanceOf(HyperLogLogCollector.class));
MatcherAssert.assertThat(sketch, CoreMatchers.instanceOf(HyperLogLogCollector.class));
}

private CursorHolder makeCursorHolder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -46,7 +47,7 @@ public void testSerialization() throws Exception
);

Object theObject = mapper.readValue(theString, Object.class);
Assert.assertThat(theObject, CoreMatchers.instanceOf(LinkedHashMap.class));
MatcherAssert.assertThat(theObject, CoreMatchers.instanceOf(LinkedHashMap.class));

LinkedHashMap theMap = (LinkedHashMap) theObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void sizesPartitionsEvenly()
int maxPartitionSize = sortedPartitionSizes.get(sortedPartitionSizes.size() - 1);
int partitionSizeRange = maxPartitionSize - minPartitionSize;

Assert.assertThat(
MatcherAssert.assertThat(
"partition sizes = " + actualPartitionSizes,
partitionSizeRange,
Matchers.is(Matchers.both(Matchers.greaterThanOrEqualTo(0)).and(Matchers.lessThanOrEqualTo(1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.druid.server.security.Resource;
import org.apache.druid.server.security.ResourceAction;
import org.apache.druid.server.security.ResourceType;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.joda.time.Interval;
import org.junit.Assert;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void serializesDeserializes()
public void hasCorrectPrefixForAutomaticId()
{
String id = target.getId();
Assert.assertThat(id, Matchers.startsWith(PartialHashSegmentGenerateTask.TYPE));
MatcherAssert.assertThat(id, Matchers.startsWith(PartialHashSegmentGenerateTask.TYPE));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.druid.timeline.partition.DimensionRangeShardSpec;
import org.apache.druid.timeline.partition.NumberedShardSpec;
import org.apache.druid.timeline.partition.SingleDimensionShardSpec;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.joda.time.Interval;
import org.junit.Assert;
Expand Down Expand Up @@ -455,14 +456,14 @@

for (StringTuple value : values) {
if (start != null) {
Assert.assertThat(value.compareTo(start), Matchers.greaterThanOrEqualTo(0));
MatcherAssert.assertThat(value.compareTo(start), Matchers.greaterThanOrEqualTo(0));

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning test

Variable
value
may be null at this access as suggested by
this
null guard.
}

if (end != null) {
if (value == null) {
Assert.assertNull("null values should be in first partition", start);
} else {
Assert.assertThat(value.compareTo(end), Matchers.lessThan(0));
MatcherAssert.assertThat(value.compareTo(end), Matchers.lessThan(0));
}
}
}
Expand Down
Loading
Loading