View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }