1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.gui;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23
24 import javax.swing.event.CellEditorListener;
25 import javax.swing.event.ChangeEvent;
26
27 import org.junit.jupiter.api.Test;
28
29 class BaseCellEditorTest {
30
31 @Test
32 public void testToString() {
33
34 final BaseCellEditor cellEditor = new BaseCellEditor();
35
36 assertWithMessage("Should return null")
37 .that(cellEditor.getCellEditorValue() == null)
38 .isTrue();
39 }
40
41 @Test
42 public void testStopCellEditing() {
43
44 final BaseCellEditor cellEditor = new BaseCellEditor();
45
46 assertWithMessage("Should be true")
47 .that(cellEditor.stopCellEditing())
48 .isTrue();
49 }
50
51 @Test
52 public void testFireEditingStoppedAndCanceled() {
53
54 final BaseCellEditor cellEditor = new BaseCellEditor();
55
56 final boolean[] cellEditorListenerStopped = {false};
57 final boolean[] cellEditorListenerCanceled = {false};
58
59 final CellEditorListener cellEditorListener1 = new CellEditorListener() {
60
61 @Override
62 public void editingStopped(ChangeEvent e) {
63 cellEditorListenerStopped[0] = true;
64 }
65
66 @Override
67 public void editingCanceled(ChangeEvent e) {
68 cellEditorListenerCanceled[0] = true;
69 }
70
71 };
72
73 cellEditor.addCellEditorListener(cellEditorListener1);
74 cellEditor.fireEditingStopped();
75 assertWithMessage("Editor listener should be stopped")
76 .that(cellEditorListenerStopped[0])
77 .isTrue();
78 cellEditor.fireEditingCanceled();
79 assertWithMessage("Editor listener should be canceled")
80 .that(cellEditorListenerCanceled[0])
81 .isTrue();
82
83 }
84 }