Tue, 28 Jul 2020 14:05:04 +0200
DocumentHandlerTest tests if modified state is reset
20 | 1 | package de.uapcore.sudoku; |
2 | ||
3 | import org.junit.jupiter.api.Test; | |
4 | ||
5 | import javax.swing.*; | |
6 | ||
7 | import static org.junit.jupiter.api.Assertions.assertEquals; | |
8 | import static org.junit.jupiter.api.Assertions.assertTrue; | |
9 | ||
10 | class ButtonPanelTest { | |
11 | ||
12 | @Test | |
13 | void testButtonsPresent() { | |
14 | final var panel = new ButtonPanel(new ActionHandler(new Field())); | |
15 | assertEquals(3, panel.getComponentCount()); | |
16 | ||
17 | assertTrue(panel.getComponent(0) instanceof JButton); | |
18 | assertEquals("Speichern", ((JButton)panel.getComponent(0)).getText()); | |
19 | assertTrue(panel.getComponent(1) instanceof JButton); | |
20 | assertEquals("Prüfen", ((JButton)panel.getComponent(1)).getText()); | |
21 | assertTrue(panel.getComponent(2) instanceof JButton); | |
22 | assertEquals("Lösen", ((JButton)panel.getComponent(2)).getText()); | |
23 | } | |
24 | ||
25 | @Test | |
26 | void testActionListener() { | |
27 | final var ah = new ActionHandler(new Field()); | |
28 | final var panel = new ButtonPanel(ah); | |
29 | assertEquals(3, panel.getComponentCount()); | |
30 | ||
31 | final var save = (JButton)panel.getComponent(0); | |
32 | final var check = (JButton)panel.getComponent(1); | |
33 | final var solve = (JButton)panel.getComponent(2); | |
34 | ||
35 | assertEquals(1, save.getActionListeners().length); | |
36 | assertEquals(ah, save.getActionListeners()[0]); | |
37 | assertEquals(1, check.getActionListeners().length); | |
38 | assertEquals(ah, check.getActionListeners()[0]); | |
39 | assertEquals(1, solve.getActionListeners().length); | |
40 | assertEquals(ah, solve.getActionListeners()[0]); | |
41 | } | |
42 | } |