Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix bug of SqlRequestFactoryTest (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
penghuo authored Sep 17, 2020
1 parent ba327d2 commit ebc10b4
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@

package com.amazon.opendistroforelasticsearch.sql.legacy.unittest;

import static java.util.Collections.emptyList;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;

import com.amazon.opendistroforelasticsearch.sql.legacy.esdomain.LocalClusterState;
import com.amazon.opendistroforelasticsearch.sql.legacy.plugin.SqlSettings;
import com.amazon.opendistroforelasticsearch.sql.legacy.request.PreparedStatementRequest;
import com.amazon.opendistroforelasticsearch.sql.legacy.request.SqlRequest;
import com.amazon.opendistroforelasticsearch.sql.legacy.request.SqlRequestFactory;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.rest.RestRequest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -34,6 +41,15 @@ public class SqlRequestFactoryTest {
@Mock
private RestRequest restRequest;

@Before
public void setup() {
SqlSettings settings = spy(new SqlSettings());
// Force return empty list to avoid ClusterSettings be invoked which is a final class and hard to mock.
// In this case, default value in Setting will be returned all the time.
doReturn(emptyList()).when(settings).getSettings();
LocalClusterState.state().setSqlSettings(settings);
}

@Ignore("RestRequest is a final method, and Mockito 1.x cannot mock it." +
"Ignore this test case till we can upgrade to Mockito 2.x")
@Test
Expand Down

0 comments on commit ebc10b4

Please sign in to comment.