src/test/java/de/uapcore/sudoku/ButtonPanelTest.java

Wed, 26 Aug 2020 19:09:07 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 26 Aug 2020 19:09:07 +0200
changeset 25
569220009c54
parent 20
a95423d37588
permissions
-rw-r--r--

fixes wrong call of assertEquals()

package de.uapcore.sudoku;

import org.junit.jupiter.api.Test;

import javax.swing.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ButtonPanelTest {

    @Test
    void testButtonsPresent() {
        final var panel = new ButtonPanel(new ActionHandler(new Field()));
        assertEquals(3, panel.getComponentCount());

        assertTrue(panel.getComponent(0) instanceof JButton);
        assertEquals("Speichern", ((JButton)panel.getComponent(0)).getText());
        assertTrue(panel.getComponent(1) instanceof JButton);
        assertEquals("Prüfen", ((JButton)panel.getComponent(1)).getText());
        assertTrue(panel.getComponent(2) instanceof JButton);
        assertEquals("Lösen", ((JButton)panel.getComponent(2)).getText());
    }

    @Test
    void testActionListener() {
        final var ah = new ActionHandler(new Field());
        final var panel = new ButtonPanel(ah);
        assertEquals(3, panel.getComponentCount());

        final var save = (JButton)panel.getComponent(0);
        final var check = (JButton)panel.getComponent(1);
        final var solve = (JButton)panel.getComponent(2);

        assertEquals(1, save.getActionListeners().length);
        assertEquals(ah, save.getActionListeners()[0]);
        assertEquals(1, check.getActionListeners().length);
        assertEquals(ah, check.getActionListeners()[0]);
        assertEquals(1, solve.getActionListeners().length);
        assertEquals(ah, solve.getActionListeners()[0]);
    }
}

mercurial