-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SquareButtonGrouppo #85
Changes from all commits
9240bf0
4c90a57
631567f
6e75317
544e254
99de81c
dccdaba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.readytalk.swt.widgets.buttons; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.MouseEvent; | ||
import org.eclipse.swt.layout.FillLayout; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Event; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class SquareButtonGroupIntegTest { | ||
|
||
private Display display; | ||
private Shell shell; | ||
|
||
private SquareButton toggleOne, toggleTwo, toggleThree, nonToggled; | ||
|
||
private SquareButtonGroup group; | ||
|
||
@Before | ||
public void setUp() { | ||
display = Display.getDefault(); | ||
shell = new Shell(display); | ||
shell.setLayout(new FillLayout()); | ||
|
||
|
||
SquareButton.SquareButtonBuilder builder = new SquareButton.SquareButtonBuilder(); | ||
builder.setParent(shell) | ||
.setText("one") | ||
.setToggleable(true); | ||
toggleOne = builder.build(); | ||
|
||
builder = new SquareButton.SquareButtonBuilder(); | ||
builder.setParent(shell) | ||
.setText("two") | ||
.setToggleable(true); | ||
toggleTwo = builder.build(); | ||
|
||
builder = new SquareButton.SquareButtonBuilder(); | ||
builder.setParent(shell) | ||
.setText("three") | ||
.setToggleable(true); | ||
toggleThree = builder.build(); | ||
|
||
builder = new SquareButton.SquareButtonBuilder(); | ||
builder.setParent(shell) | ||
.setText("non toggle"); | ||
nonToggled = builder.build(); | ||
|
||
group = new SquareButtonGroup(toggleOne, toggleTwo, toggleThree, nonToggled); | ||
|
||
shell.open(); | ||
} | ||
|
||
@Test | ||
public void testDefaultToggle() { | ||
Assert.assertTrue(toggleOne.isToggled()); | ||
Assert.assertFalse(toggleTwo.isToggled()); | ||
Assert.assertFalse(toggleThree.isToggled()); | ||
Assert.assertFalse(nonToggled.isToggled()); | ||
} | ||
|
||
@Test | ||
public void testBasicToggle() { | ||
toggleTwo.notifyListeners(SWT.MouseUp, new Event()); | ||
Assert.assertFalse(toggleOne.isToggled()); | ||
Assert.assertTrue(toggleTwo.isToggled()); | ||
Assert.assertFalse(toggleThree.isToggled()); | ||
Assert.assertFalse(nonToggled.isToggled()); | ||
} | ||
|
||
@Test | ||
public void testDoubleToggle() { | ||
toggleTwo.notifyListeners(SWT.MouseUp, new Event()); | ||
Assert.assertFalse(toggleOne.isToggled()); | ||
Assert.assertTrue(toggleTwo.isToggled()); | ||
Assert.assertFalse(toggleThree.isToggled()); | ||
Assert.assertFalse(nonToggled.isToggled()); | ||
|
||
toggleTwo.notifyListeners(SWT.MouseUp, new Event()); | ||
Assert.assertFalse(toggleOne.isToggled()); | ||
Assert.assertTrue(toggleTwo.isToggled()); | ||
Assert.assertFalse(toggleThree.isToggled()); | ||
Assert.assertFalse(nonToggled.isToggled()); | ||
} | ||
|
||
@Test | ||
public void testForcedSelection() { | ||
group.setCurrentlyToggledButton(toggleThree); | ||
Assert.assertFalse(toggleOne.isToggled()); | ||
Assert.assertFalse(toggleTwo.isToggled()); | ||
Assert.assertTrue(toggleThree.isToggled()); | ||
Assert.assertFalse(nonToggled.isToggled()); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be good to add an additional test to ensure that if you click the same button twice, it's still toggled. That was the original problem that brought up the SquareButtonGroup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, I can do that. It works in the example, but I can check it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I saw that. The example looks to do exactly what I was hoping. Good to enforce that behavior in the test, too. |
||
@After | ||
public void tearDown() { | ||
shell.close(); | ||
display.dispose(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to discourage users of SquareButton from using
addMouseListener
in favor ofsetDefaultMouseClickAndReturnKeyHandler
? If so, we might want to document that somewhere, or forbid them from doing it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will discourage them via @deprecated and a note... thoughts?