SegmentUtils { public static boolean evaluateSegmentation(Campaign campaign) { if (campaign.getSegmentType() == null) { return false; } if (campaign.getSegmentType().equals(Campaign.SEGMENT_CUSTOM)) { List<Object> expression = new ArrayList<>(); for (Segment segment : campaign.getSegments()) { CustomSegment customSegment = (CustomSegment) segment; expression.addAll(customSegment.toInfix()); } if (expression.get(0) instanceof Operator && ((Operator) expression.get(0)).canEvaluate()) { expression.remove(0); } InfixExpressionEvaluator infixExpressionEvaluator = new InfixExpressionEvaluator(expression); return infixExpressionEvaluator.evaluate(); } else { return campaign.getSegments().get(0).evaluate(); } }  static boolean evaluateSegmentation(Campaign campaign);  }
@Test public void campaignNoSegmentation() throws IOException, JSONException { String data = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign_no_segmentation.json"); Campaign campaign = new Campaign(vwo, new JSONObject(data)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign)); }
@Test public void test1() throws JSONException, IOException { String data = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign1.json"); Campaign campaign = new Campaign(vwo, new JSONObject(data)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign)); }
@Test public void test2() throws IOException, JSONException { String data2 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign2.json"); Campaign campaign2 = new Campaign(vwo, new JSONObject(data2)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign2)); }
@Test public void test3() throws IOException, JSONException { String data3 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign3.json"); Campaign campaign3 = new Campaign(vwo, new JSONObject(data3)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign3)); }
@Test public void test4() throws IOException, JSONException { String data4 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign4.json"); Campaign campaign4 = new Campaign(vwo, new JSONObject(data4)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign4)); }
@Test public void test5() throws IOException, JSONException { String data5 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign5.json"); Campaign campaign5 = new Campaign(vwo, new JSONObject(data5)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign5)); }
@Test public void test6() throws IOException, JSONException { String data6 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign6.json"); Campaign campaign6 = new Campaign(vwo, new JSONObject(data6)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign6)); }
@Test public void test7() throws IOException, JSONException { String data7 = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign7.json"); Campaign campaign7 = new Campaign(vwo, new JSONObject(data7)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign7)); }
@Test public void test8() throws IOException, JSONException { String campaignIdMissing = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign_id_missing.json"); Campaign campaign9 = new Campaign(vwo, new JSONObject(campaignIdMissing)); Assert.assertFalse(SegmentUtils.evaluateSegmentation(campaign9)); }
@Test public void test9() throws IOException, JSONException { String campaignStatusMissing = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign_status_missing.json"); Campaign campaign11 = new Campaign(vwo, new JSONObject(campaignStatusMissing)); Assert.assertTrue(SegmentUtils.evaluateSegmentation(campaign11)); }
@Test public void excludedCampaignTest() throws IOException, JSONException { String campaignExcluded = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign_excluded.json"); Campaign campaign8 = new Campaign(vwo, new JSONObject(campaignExcluded)); Assert.assertFalse(SegmentUtils.evaluateSegmentation(campaign8)); }
@Test public void pausedCampaignTest() throws JSONException, IOException { String campaignPaused = TestUtils.readJsonFile(getClass(), "com/vwo/mobile/segmentation/campaign_paused.json"); Campaign campaign10 = new Campaign(vwo, new JSONObject(campaignPaused)); Assert.assertFalse(SegmentUtils.evaluateSegmentation(campaign10)); }