Skip to content

Commit

Permalink
Issue checkstyle#11514: Add test cases to base cell editor
Browse files Browse the repository at this point in the history
  • Loading branch information
pymoura committed May 21, 2023
1 parent 1ae08b8 commit 50de524
Showing 1 changed file with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,59 @@

import static com.google.common.truth.Truth.assertWithMessage;

import org.junit.jupiter.api.Test;

import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;

import org.junit.jupiter.api.Test;

class BaseCellEditorTest {

private BaseCellEditor bce = new BaseCellEditor();
private final BaseCellEditor bce = new BaseCellEditor();

@Test
void testToString() {
public void testToString() {
assertWithMessage("is null")
.that(bce.getCellEditorValue() == null)
.isEqualTo(true);
}

@Test
public void testStopCellEditing() {
assertWithMessage("StopEditing return true")
.that(bce.stopCellEditing())
.isEqualTo(true);
}

@Test
public void testFireEditingStoppedAndCanceled() {

final boolean[] cellEditorListenerStopped = {false};
final boolean[] cellEditorListenerCanceled = {false};

final CellEditorListener cellEditorListener1 = new CellEditorListener() {

@Override
public void editingStopped(ChangeEvent e) {
cellEditorListenerStopped[0] = true;

}

@Override
public void editingCanceled(ChangeEvent e) {
cellEditorListenerCanceled[0] = true;

}

};

bce.addCellEditorListener(cellEditorListener1);
bce.fireEditingStopped();
assertWithMessage("Check if editing listener has stopped")
.that(cellEditorListenerStopped[0]).isEqualTo(true);
bce.fireEditingCanceled();
assertWithMessage("Check if editing listener has canceled")
.that(cellEditorListenerCanceled[0]).isEqualTo(true);
bce.removeCellEditorListener(cellEditorListener1);

}
}

0 comments on commit 50de524

Please sign in to comment.