CustomSegment extends Segment { public List<Object> toInfix() { List<Object> list = new ArrayList<>(); if (getPreviousLogicalOperator() != null) { list.add(getPreviousLogicalOperator()); } if (hasLeftBracket()) { list.add(Operator.OPEN_PARENTHESES); } list.add(evaluate()); if (hasRightBracket()) { list.add(Operator.CLOSE_PARENTHESES); } return list; } CustomSegment(VWO vwo, JSONObject segment); @Nullable Operator getPreviousLogicalOperator(); @Nullable String getType(); @Override boolean evaluate(); @Override boolean isCustomSegment(); List<Object> toInfix();  }
@Test @Config(sdk = 17) public void toInfixTest() throws JSONException, IOException { VWO vwo = new VWOMock().getVWOMockObject(); String equal1 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/to_infix1.json"); CustomSegment segmentEqual1 = new CustomSegment(vwo, new JSONObject(equal1)); Object[] expectedValue1 = {Boolean.TRUE}; Assert.assertEquals(Arrays.asList(expectedValue1).toString(), segmentEqual1.toInfix().toString()); String equalToTrue = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/to_infix2.json"); CustomSegment segmentEqualToTrue = new CustomSegment(vwo, new JSONObject(equalToTrue)); List<Object> expectedValueArray = new ArrayList<>(); expectedValueArray.add(AND); expectedValueArray.add(OPEN_PARENTHESES); expectedValueArray.add(Boolean.TRUE); expectedValueArray.add(CLOSE_PARENTHESES); Assert.assertEquals(expectedValueArray.toString(), segmentEqualToTrue.toInfix().toString()); String data2 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/to_infix3.json"); CustomSegment segment2 = new CustomSegment(vwo, new JSONObject(data2)); Object[] expectedValue2 = {AND, Boolean.TRUE, CLOSE_PARENTHESES}; Assert.assertEquals(Arrays.asList(expectedValue2).toString(), segment2.toInfix().toString()); String equal3 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/to_infix4.json"); CustomSegment segmentEqual3 = new CustomSegment(vwo, new JSONObject(equal3)); Object[] expectedValue3 = {AND, Boolean.TRUE}; Assert.assertEquals(Arrays.asList(expectedValue3).toString(), segmentEqual3.toInfix().toString()); }