@@ -0,0 +1,2645 @@
+package org.flymine.sql.precompute;%0A%0Aimport junit.framework.*;%0Aimport org.flymine.sql.query.*;%0A%0Apublic class BestQueryExplainerTest extends TestCase%0A%7B%0A    private Query q1, q2;%0A%0A    public BestQueryExplainerTest(String arg1) %7B%0A        super(arg1);%0A    %7D%0A%0A    public void setUp() %7B%0A        q1 = new Query();%0A        Table t = new Table(%22mytable%22);%0A        Constant c = new Constant(%221%22);%0A        Field f = new Field(%22a%22, t);%0A        SelectValue sv = new SelectValue(f, null);%0A        q1.addFrom(t);%0A        q1.addSelect(sv);%0A        q1.addWhere(new Constraint(f, Constraint.EQ, c));%0A%0A        q2 = new Query();%0A        Table t1 = new Table(%22mytable%22);%0A        Table t2 = new Table(%22mytable%22);%0A        Field f1 = new Field(%22a%22, t1);%0A        Field f2 = new Field(%22b%22, t2);%0A        sv = new SelectValue(f1, null);%0A        q2.addFrom(t1);%0A        q2.addFrom(t2);%0A        q2.addSelect(sv);%0A        q2.addWhere(new Constraint(f1, Constraint.EQ, c));%0A        q2.addWhere(new Constraint(f2, Constraint.EQ, c));%0A    %7D%0A%0A    public void testNullConstructor() throws Exception %7B%0A        BestQueryExplainer bq;%0A        try %7B%0A            bq = new BestQueryExplainer(null);%0A            fail(%22Expected: NullPointerException%22);%0A        %7D%0A        catch (NullPointerException e) %7B%0A        %7D%0A    %7D%0A%0A    public void testNullBestQueryForNoneAdded() throws Exception %7B%0A        BestQueryExplainer bq = new BestQueryExplainer();%0A        assertNull(bq.getBestQuery());%0A        assertNull(bq.getBestExplainResult());%0A    %7D%0A%0A    public void testAddNull() throws Exception %7B%0A        BestQueryExplainer bq = new BestQueryExplainer();%0A        try %7B%0A            bq.add(null);%0A            fail(%22Expected: NullPointerException%22);%0A        %7D%0A        catch (NullPointerException e) %7B%0A        %7D%0A    %7D%0A%0A    public void testReturnFirst() throws Exception %7B%0A        BestQueryExplainer bq = new BestQueryExplainer();%0A        bq.add(q1);%0A        assertEquals(q1, bq.getBestQuery());%0A    %7D%0A%0A    public void testReturnBest() throws Exception %7B%0A        BestQueryExplainer bq = new BestQueryExplainer();%0A        bq.add(q1);%0A        bq.add(q2);%0A        assertEquals(q1, bq.getBestQuery());%0A%0A        bq = new BestQueryExplainer();%0A        bq.add(q2);%0A        bq.add(q1);%0A        assertEquals(q1, bq.getBestQuery());%0A    %7D%0A%0A    public void testStopsWhenQueryBetterThanElapsed() throws Exception %7B%0A        BestQueryExplainer bq = new BestQueryExplainer();%0A        bq.add(q1); // Takes 3 milliseconds%0A        Thread.currentThread().sleep(10);%0A        try %7B%0A            bq.add(q2);%0A            fail(%22Expected: BestQueryException%22);%0A        %7D%0A        catch (BestQueryException e) %7B%0A        %7D%0A    %7D%0A%0A%7D%0A

Test class for BestQueryExplainer