Skip to content

Commit

Permalink
fix jacoco test
Browse files Browse the repository at this point in the history
Signed-off-by: panguixin <[email protected]>
  • Loading branch information
bugmakerrrrrr committed Jul 16, 2024
1 parent e8fa1cd commit 634d577
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public Pair<Double, Double> geoValue() {
NamedXContentRegistry.EMPTY,
DeprecationHandler.IGNORE_DEPRECATIONS,
value.traverse())) {
assert parser.currentToken() == null;
parser.nextToken();
GeoPoint point = new GeoPoint();
GeoUtils.parseGeoPoint(parser, point, true);
Expand All @@ -149,16 +148,4 @@ public Pair<Double, Double> geoValue() {
private JsonNode value() {
return value;
}

/** Get doubleValue from JsonNode if possible. */
private Double extractDoubleValue(JsonNode node) {
if (node.isTextual()) {
return Double.valueOf(node.textValue());
}
if (node.isNumber()) {
return node.doubleValue();
} else {
throw new IllegalStateException("node must be a number");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.opensearch.sql.opensearch.data.type.OpenSearchBinaryType;
import org.opensearch.sql.opensearch.data.type.OpenSearchDataType;
import org.opensearch.sql.opensearch.data.type.OpenSearchDateType;
import org.opensearch.sql.opensearch.data.type.OpenSearchGeoPointType;
import org.opensearch.sql.opensearch.data.type.OpenSearchIpType;
import org.opensearch.sql.opensearch.data.utils.Content;
import org.opensearch.sql.opensearch.data.utils.ObjectContent;
Expand Down Expand Up @@ -419,8 +418,7 @@ private ExprValue parseInnerArrayValue(
Content content, String prefix, ExprType type, boolean supportArrays) {
if (type instanceof OpenSearchIpType
|| type instanceof OpenSearchBinaryType
|| type instanceof OpenSearchDateType
|| type instanceof OpenSearchGeoPointType) {
|| type instanceof OpenSearchDateType) {
return parse(content, prefix, Optional.of(type), supportArrays);
} else if (content.isString()) {
return parse(content, prefix, Optional.of(OpenSearchDataType.of(STRING)), supportArrays);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.opensearch.data.utils;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.opensearch.OpenSearchParseException;

public class OpenSearchJsonContentTest {
@Test
public void testGetValueWithIOException() throws IOException {
JsonNode jsonNode = mock(JsonNode.class);
JsonParser jsonParser = mock(JsonParser.class);
when(jsonNode.traverse()).thenReturn(jsonParser);
when(jsonParser.nextToken()).thenThrow(new IOException());
OpenSearchJsonContent content = new OpenSearchJsonContent(jsonNode);
OpenSearchParseException exception =
assertThrows(OpenSearchParseException.class, content::geoValue);
assertTrue(exception.getMessage().contains("error parsing geo point"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,18 @@ public void constructArrayOfGeoPoints() {
.get("geoV"));
}

@Test
public void constructArrayOfGeoPointsReturnsFirstIndex() {
assertEquals(
new OpenSearchExprGeoPointValue(42.60355556, -97.25263889),
tupleValue(
"{\"geoV\":["
+ "{\"lat\":42.60355556,\"lon\":-97.25263889},"
+ "{\"lat\":-33.6123556,\"lon\":66.287449}"
+ "]}")
.get("geoV"));
}

@Test
public void constructArrayOfIPsReturnsFirstIndex() {
assertEquals(
Expand Down

0 comments on commit 634d577

Please sign in to comment.