/** * Tests that when a repeated ORDER BY clause is added to the selector, it is actually ignored. */ @Test public void testOrderBySubstitution() { SelectorBuilder builder = new SelectorBuilder(); builder = builder.orderAscBy(CampaignField.BidType).orderDescBy(CampaignField.Amount); Selector selector = builder.build(); assertNotNull(selector.getOrdering()); assertEquals(2, selector.getOrdering().length); builder.orderAscBy(CampaignField.BidType); selector = builder.build(); assertNotNull(selector.getOrdering()); assertEquals(2, selector.getOrdering().length); OrderBy orderBy = selector.getOrdering()[0]; assertEquals("BidType", orderBy.getField()); assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder()); orderBy = selector.getOrdering()[1]; assertEquals("Amount", orderBy.getField()); assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder()); }
/** Tests that the built selectors don't share internal OrderBy state. */ @Test public void testUniqueInternalOrderByState() { SelectorBuilder builder = new SelectorBuilder(); Selector selectorOne = builder.orderAscBy(CampaignField.Id).build(); Selector selectorTwo = builder.build(); OrderBy orderTwo = selectorTwo.getOrdering(0); orderTwo.setField("Status"); assertEquals("Id", selectorOne.getOrdering(0).getField()); assertEquals("Status", selectorTwo.getOrdering(0).getField()); }
/** Tests the order by criteria */ @Test public void testOrderByBuild() { SelectorBuilder builder = new SelectorBuilder(); builder = builder.orderAscBy(CampaignField.BidType); Selector selector = builder.build(); assertNotNull(selector.getOrdering()); assertEquals(1, selector.getOrdering().length); OrderBy orderBy = selector.getOrdering()[0]; assertEquals("BidType", orderBy.getField()); assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder()); builder.orderAscBy(CampaignField.Amount).orderDescBy(CampaignField.BidType); selector = builder.build(); assertNotNull(selector.getOrdering()); assertEquals(3, selector.getOrdering().length); orderBy = selector.getOrdering()[0]; assertEquals("BidType", orderBy.getField()); assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder()); orderBy = selector.getOrdering()[1]; assertEquals("Amount", orderBy.getField()); assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder()); orderBy = selector.getOrdering()[2]; assertEquals("BidType", orderBy.getField()); assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder()); // Removing the OrderBy for BidType selector = builder.removeOrderBy("BidType").build(); assertNotNull(selector.getOrdering()); assertEquals(1, selector.getOrdering().length); orderBy = selector.getOrdering()[0]; assertEquals("Amount", orderBy.getField()); assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder()); }