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

Tue, 28 Jul 2020 14:44:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 28 Jul 2020 14:44:48 +0200
changeset 23
07b9adaed78e
parent 20
a95423d37588
permissions
-rw-r--r--

adds solver test

20
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 package de.uapcore.sudoku;
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 import org.junit.jupiter.api.Test;
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 import javax.swing.*;
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 import static org.junit.jupiter.api.Assertions.assertEquals;
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 import static org.junit.jupiter.api.Assertions.assertTrue;
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 class ButtonPanelTest {
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 @Test
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 void testButtonsPresent() {
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 final var panel = new ButtonPanel(new ActionHandler(new Field()));
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 assertEquals(3, panel.getComponentCount());
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 assertTrue(panel.getComponent(0) instanceof JButton);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 assertEquals("Speichern", ((JButton)panel.getComponent(0)).getText());
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 assertTrue(panel.getComponent(1) instanceof JButton);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 assertEquals("Prüfen", ((JButton)panel.getComponent(1)).getText());
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 assertTrue(panel.getComponent(2) instanceof JButton);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 assertEquals("Lösen", ((JButton)panel.getComponent(2)).getText());
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 }
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 @Test
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 void testActionListener() {
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 final var ah = new ActionHandler(new Field());
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 final var panel = new ButtonPanel(ah);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 assertEquals(3, panel.getComponentCount());
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 final var save = (JButton)panel.getComponent(0);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 final var check = (JButton)panel.getComponent(1);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 final var solve = (JButton)panel.getComponent(2);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 assertEquals(1, save.getActionListeners().length);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 assertEquals(ah, save.getActionListeners()[0]);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 assertEquals(1, check.getActionListeners().length);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 assertEquals(ah, check.getActionListeners()[0]);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 assertEquals(1, solve.getActionListeners().length);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 assertEquals(ah, solve.getActionListeners()[0]);
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 }
a95423d37588 adds more tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 }

mercurial