Tue, 28 Jul 2020 14:44:48 +0200
adds solver test
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.assertNull; | |
9 | ||
10 | class MainMenuTest { | |
11 | ||
12 | private final ActionHandler actionHandler = new ActionHandler(new Field()); | |
13 | ||
14 | private void testListeners(JMenuItem m) { | |
15 | final var listeners = m.getActionListeners(); | |
16 | assertEquals(1, listeners.length); | |
17 | assertEquals(actionHandler, listeners[0]); | |
18 | } | |
19 | ||
20 | @Test | |
21 | void testStructure() { | |
22 | final var menu = new MainMenu(actionHandler); | |
23 | ||
24 | assertEquals(2, menu.getMenuCount()); | |
25 | ||
26 | final var datei = menu.getMenu(0); | |
27 | assertEquals('D', datei.getMnemonic()); | |
28 | assertEquals(9, datei.getItemCount()); | |
29 | { | |
30 | final var item = datei.getItem(0); | |
31 | assertEquals("Neu", item.getText()); | |
32 | assertEquals('N', item.getMnemonic()); | |
33 | assertEquals(1, item.getRegisteredKeyStrokes().length); | |
34 | assertEquals(KeyStroke.getKeyStroke("control N"), item.getRegisteredKeyStrokes()[0]); | |
35 | testListeners(item); | |
36 | } | |
37 | { | |
38 | final var item = datei.getItem(1); | |
39 | assertEquals("Öffnen", item.getText()); | |
40 | assertEquals('F', item.getMnemonic()); | |
41 | assertEquals(1, item.getRegisteredKeyStrokes().length); | |
42 | assertEquals(KeyStroke.getKeyStroke("control O"), item.getRegisteredKeyStrokes()[0]); | |
43 | testListeners(item); | |
44 | } | |
45 | { | |
46 | final var item = datei.getItem(2); | |
47 | assertEquals("Speichern", item.getText()); | |
48 | assertEquals('S', item.getMnemonic()); | |
49 | assertEquals(1, item.getRegisteredKeyStrokes().length); | |
50 | assertEquals(KeyStroke.getKeyStroke("control S"), item.getRegisteredKeyStrokes()[0]); | |
51 | testListeners(item); | |
52 | } | |
53 | { | |
54 | final var item = datei.getItem(3); | |
55 | assertEquals("Speichern als...", item.getText()); | |
56 | assertEquals('A', item.getMnemonic()); | |
57 | testListeners(item); | |
58 | } | |
59 | ||
60 | assertNull(datei.getItem(4)); | |
61 | { | |
62 | final var item = datei.getItem(5); | |
63 | assertEquals("Prüfen", item.getText()); | |
64 | assertEquals('P', item.getMnemonic()); | |
65 | assertEquals(1, item.getRegisteredKeyStrokes().length); | |
66 | assertEquals(KeyStroke.getKeyStroke("control P"), item.getRegisteredKeyStrokes()[0]); | |
67 | testListeners(item); | |
68 | } | |
69 | { | |
70 | final var item = datei.getItem(6); | |
71 | assertEquals("Lösen", item.getText()); | |
72 | assertEquals('L', item.getMnemonic()); | |
73 | assertEquals(1, item.getRegisteredKeyStrokes().length); | |
74 | assertEquals(KeyStroke.getKeyStroke("control L"), item.getRegisteredKeyStrokes()[0]); | |
75 | testListeners(item); | |
76 | } | |
77 | assertNull(datei.getItem(7)); | |
78 | { | |
79 | final var item = datei.getItem(8); | |
80 | assertEquals("Beenden", item.getText()); | |
81 | assertEquals('E', item.getMnemonic()); | |
82 | testListeners(item); | |
83 | } | |
84 | ||
85 | final var info = menu.getMenu(1); | |
86 | assertEquals("Info", info.getText()); | |
87 | assertEquals('I', info.getMnemonic()); | |
88 | ||
89 | assertEquals(1, info.getItemCount()); | |
90 | final var about = info.getItem(0); | |
91 | assertEquals("Über...", about.getText()); | |
92 | assertEquals('B', about.getMnemonic()); | |
93 | assertEquals(1, about.getRegisteredKeyStrokes().length); | |
94 | assertEquals(KeyStroke.getKeyStroke("F1"), about.getRegisteredKeyStrokes()[0]); | |
95 | testListeners(about); | |
96 | } | |
97 | } |