Logo Search packages:      
Sourcecode: pauker version File versions  Download package

void pauker::program::gui::swing::UnLearnTest::testUnlearn (  )  throws Exception [inline]

runs the test

Exceptions:
java.lang.Exception if an exception occurs

Definition at line 34 of file UnLearnTest.java.

References pauker::program::gui::swing::PaukerFrame::getCurrentLesson(), and pauker::program::gui::swing::PaukerFrame::loadBatch().

                                               {

        assertFalse("Only screenshots are generated!", Screenshots.UPDATE_SCREENSHOTS);

        // set up exception handler
        MyUEH myUEH = new MyUEH();
        Thread.setDefaultUncaughtExceptionHandler(myUEH);

        ResourceBundle strings = ResourceBundle.getBundle("pauker/Strings");

        // get path of test lesson
        String internalPath = "/testLessons/Riesentest.xml.gz";
        String testFilePath = getClass().getResource(internalPath).getPath();

        ClassReference classReference = new ClassReference(
                "pauker.program.gui.swing.PaukerFrame");
        classReference.startApplication(new String[]{testFilePath});
        JFrameOperator frameOperator = new JFrameOperator();
        PaukerFrame paukerFrame = (PaukerFrame) frameOperator.getSource();
        JLabelOperator notLearnedLabelOperator = new JLabelOperator(
                frameOperator, new NameComponentChooser("notLearnedLabel"));
        JComponentOperator batchPanelOperator = new JComponentOperator(
                frameOperator, new NameComponentChooser("batchPanel"));
        TitledBorder batchBanelBorder = (TitledBorder) batchPanelOperator.getBorder();
        JLabelOperator firstLongTermBatchLabelOperator = new JLabelOperator(
                frameOperator, new NameComponentChooser("longTermBatchLabel0"));
        JListOperator batchListOperator = new JListOperator(
                frameOperator, new NameComponentChooser("batchList"));
        JButtonOperator instantRepeatButtonOperator = new JButtonOperator(
                frameOperator, new NameComponentChooser("instantRepeatButton"));
        JButtonOperator learnNewCardsButtonOperator = new JButtonOperator(
                frameOperator, new NameComponentChooser("learnNewCardsButton"));
        JButtonOperator forgetButtonOperator = new JButtonOperator(
                frameOperator, new NameComponentChooser("forgetButton"));
        JButtonOperator fontButtonOperator = new JButtonOperator(
                frameOperator, new NameComponentChooser("fontButton"));
        JButtonOperator learningMethodButtonOperator = new JButtonOperator(
                frameOperator, new NameComponentChooser("learningMethodButton"));
        JButtonOperator repeatCardsButtonOperator = new JButtonOperator(
                frameOperator, new NameComponentChooser("repeatCardsButton"));

        assertEquals("there was an exception on startup!",
                0, myUEH.getCounter());

        // select unlearned batch
        Tools.clickComponentOperator(notLearnedLabelOperator);
        batchPanelOperator.waitComponentShowing(true);
        assertEquals(strings.getString("Not_learned"), batchBanelBorder.getTitle());

        // select first long term batch
        Tools.clickComponentOperator(firstLongTermBatchLabelOperator);
        Thread.sleep(1000);
        String title = strings.getString("Batch") + ' ' + 1;
        assertEquals(title, batchBanelBorder.getTitle());

        // programmatically load unlearned batch again
        Lesson currentLesson = paukerFrame.getCurrentLesson();
        paukerFrame.loadBatch(currentLesson.getUnlearnedBatch());

        // instant repeat all unlearned cards
        ListModel listModel = batchListOperator.getModel();
        int size = listModel.getSize();
        batchListOperator.setSelectionInterval(0, size - 1);
        instantRepeatButtonOperator.waitComponentEnabled();
        instantRepeatButtonOperator.pushNoBlock();
        JDialogOperator dialogOperator = new JDialogOperator();
        JButtonOperator confirmButtonOperator = new JButtonOperator(
                dialogOperator, strings.getString("Repeat_Cards_Instantly"));
        long start = System.currentTimeMillis();
        Tools.doClick(confirmButtonOperator);
        assertFalse(fontButtonOperator.isEnabled());
        assertFalse(learningMethodButtonOperator.isEnabled());
        repeatCardsButtonOperator.waitComponentEnabled();
        long stop = System.currentTimeMillis();
        long instantRepeatTime = stop - start;

        // now move them all back to the unlearned batch
        paukerFrame.loadBatch(currentLesson.getLongTermBatch(0));
        listModel = batchListOperator.getModel();
        size = listModel.getSize();
        batchListOperator.setSelectionInterval(0, size - 1);
        forgetButtonOperator.waitComponentEnabled();
        forgetButtonOperator.pushNoBlock();
        dialogOperator = new JDialogOperator();
        confirmButtonOperator = new JButtonOperator(
                dialogOperator, strings.getString("Move_Cards_Back"));
        start = System.currentTimeMillis();
        Tools.doClick(confirmButtonOperator);
        assertFalse(repeatCardsButtonOperator.isEnabled());
        assertFalse(fontButtonOperator.isEnabled());
        assertFalse(learningMethodButtonOperator.isEnabled());
        assertTrue(learnNewCardsButtonOperator.isEnabled());
        stop = System.currentTimeMillis();
        long unlearnTime = stop - start;

        // check that instant repeat and unlearn do not differ substantially in time
        long max = Math.max(instantRepeatTime, unlearnTime);
        long min = Math.min(instantRepeatTime, unlearnTime);

        assertTrue("times for instant repeat (" + instantRepeatTime +
                "ms) and unlearn (" + unlearnTime + 
                " ms) differ substantially!", (max / min) < 4);
    }


Generated by  Doxygen 1.6.0   Back to index