forked from searchbox-io/Jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Seth Abrams
committed
May 1, 2018
1 parent
ce1b632
commit 6e4239d
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
jest-common/src/test/java/io/searchbox/search/aggregation/CardinalityAggregationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.searchbox.search.aggregation; | ||
|
||
import com.google.gson.JsonObject; | ||
import io.searchbox.core.search.aggregation.CardinalityAggregation; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class CardinalityAggregationTest { | ||
@Test | ||
public void givenMissingValueProperty_cardinalityAggregationConstructor_doesNotAssignToCardinalityField() { | ||
JsonObject cardinalityAggregationJson = new JsonObject(); | ||
cardinalityAggregationJson.addProperty("notValueField", "hi"); | ||
cardinalityAggregationJson.addProperty("anotherField", "hello"); | ||
CardinalityAggregation cardinalityAggregation = new CardinalityAggregation("aggName", cardinalityAggregationJson); | ||
assertNull("Cardinality field should default to null since value is unassigned", cardinalityAggregation.getCardinality()); | ||
} | ||
|
||
@Test | ||
public void givenNullValueProperty_cardinalityAggregationConstructor_doesNotAssignToCardinalityField() { | ||
JsonObject cardinalityAggregationJson = new JsonObject(); | ||
cardinalityAggregationJson.addProperty("notValueField", "hi"); | ||
cardinalityAggregationJson.addProperty("anotherField", "hello"); | ||
String nullString = null; | ||
cardinalityAggregationJson.addProperty("value", nullString); | ||
CardinalityAggregation cardinalityAggregation = new CardinalityAggregation("aggName", cardinalityAggregationJson); | ||
assertNull("Cardinality field should default to null since value is null", cardinalityAggregation.getCardinality()); | ||
} | ||
|
||
@Test | ||
public void givenNonNullValueProperty_cardinalityAggregationConstructor_assignsToCardinalityField() { | ||
JsonObject cardinalityAggregationJson = new JsonObject(); | ||
cardinalityAggregationJson.addProperty("notValueField", "hi"); | ||
cardinalityAggregationJson.addProperty("anotherField", "hello"); | ||
Long setValue = 100L; | ||
cardinalityAggregationJson.addProperty("value", setValue); | ||
CardinalityAggregation cardinalityAggregation = new CardinalityAggregation("aggName", cardinalityAggregationJson); | ||
assertEquals(setValue, cardinalityAggregation.getCardinality()); | ||
} | ||
} |