Skip to content

Commit

Permalink
Skip tests that aren't compatible with mockito on JDK8.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Mar 10, 2022
1 parent 760adca commit 7dc1b1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
Expand Down Expand Up @@ -98,26 +99,6 @@ public class IndexAnomalyDetectorActionHandlerTests extends AbstractADTest {
private ADTaskManager adTaskManager;
private SearchFeatureDao searchFeatureDao;

/**
* Mockito does not allow mock final methods. Make my own delegates and mock them.
*
*/
class NodeClientDelegate extends NodeClient {

NodeClientDelegate(Settings settings, ThreadPool threadPool) {
super(settings, threadPool);
}

public <Request extends ActionRequest, Response extends ActionResponse> void execute2(
ActionType<Response> action,
Request request,
ActionListener<Response> listener
) {
super.execute(action, request, listener);
}

}

@BeforeClass
public static void beforeClass() {
threadPool = new TestThreadPool("IndexAnomalyDetectorJobActionHandlerTests");
Expand Down Expand Up @@ -201,6 +182,8 @@ public void testThreeCategoricalFields() throws IOException {

@SuppressWarnings("unchecked")
public void testMoreThanTenThousandSingleEntityDetectors() throws IOException {
Assume.assumeTrue(System.getProperty("java.specification.version").compareTo("1.9") >= 0);

SearchResponse mockResponse = mock(SearchResponse.class);
int totalHits = 1001;
when(mockResponse.getHits()).thenReturn(TestHelpers.createSearchHits(totalHits));
Expand Down Expand Up @@ -555,6 +538,8 @@ public <Request extends ActionRequest, Response extends ActionResponse> void doE

@SuppressWarnings("unchecked")
public void testMoreThanTenMultiEntityDetectors() throws IOException {
Assume.assumeTrue(System.getProperty("java.specification.version").compareTo("1.9") >= 0);

String field = "a";
AnomalyDetector detector = TestHelpers.randomAnomalyDetectorUsingCategoryFields(detectorId, Arrays.asList(field));
SearchResponse detectorResponse = mock(SearchResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Locale;

import org.junit.Assume;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
Expand Down Expand Up @@ -125,6 +126,8 @@ public void setUp() throws Exception {

@SuppressWarnings("unchecked")
public void testValidateMoreThanThousandSingleEntityDetectorLimit() throws IOException {
Assume.assumeTrue(System.getProperty("java.specification.version").compareTo("1.9") >= 0);

SearchResponse mockResponse = mock(SearchResponse.class);
int totalHits = maxSingleEntityAnomalyDetectors + 1;
when(mockResponse.getHits()).thenReturn(TestHelpers.createSearchHits(totalHits));
Expand Down Expand Up @@ -205,6 +208,8 @@ public void testValidateMoreThanThousandSingleEntityDetectorLimit() throws IOExc

@SuppressWarnings("unchecked")
public void testValidateMoreThanTenMultiEntityDetectorsLimit() throws IOException {
Assume.assumeTrue(System.getProperty("java.specification.version").compareTo("1.9") >= 0);

String field = "a";
AnomalyDetector detector = TestHelpers.randomAnomalyDetectorUsingCategoryFields(detectorId, Arrays.asList(field));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.opensearch.OpenSearchStatusException;
Expand Down Expand Up @@ -143,6 +144,8 @@ public void testStartHistoricalAnalysisWithUser() throws IOException {
}

public void testStartHistoricalAnalysisForSingleCategoryHCWithUser() throws IOException, InterruptedException {
Assume.assumeTrue(System.getProperty("java.specification.version").compareTo("1.9") >= 0);

ingestTestData(testIndex, startTime, detectionIntervalInMinutes, type + "1", DEFAULT_IP, 2000, false);
ingestTestData(testIndex, startTime, detectionIntervalInMinutes, type + "2", DEFAULT_IP, 2000, false);
AnomalyDetector detector = TestHelpers
Expand Down

0 comments on commit 7dc1b1e

Please sign in to comment.