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

Tue, 28 Jul 2020 13:48:59 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 28 Jul 2020 13:48:59 +0200
changeset 20
a95423d37588
permissions
-rw-r--r--

adds more tests

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

mercurial