public void test(TestHarness harness)
{
ButtonGroup g = new ButtonGroup();
// add a button that is not selected
JToggleButton b1 = new JToggleButton("B1");
g.add(b1);
harness.check(g.getButtonCount(), 1);
harness.check(g.getSelection(), null);
harness.check(((DefaultButtonModel) b1.getModel()).getGroup(), g);
// add a button that is selected
JToggleButton b2 = new JToggleButton("B2");
b2.setSelected(true);
g.add(b2);
harness.check(g.getButtonCount(), 2);
harness.check(g.getSelection(), b2.getModel());
harness.check(((DefaultButtonModel) b2.getModel()).getGroup(), g);
// add another button that is selected
JToggleButton b3 = new JToggleButton("B2");
b3.setSelected(true);
g.add(b3);
harness.check(g.getButtonCount(), 3);
harness.check(g.getSelection(), b2.getModel());
harness.check(b2.isSelected(), true);
harness.check(b3.isSelected(), false);
harness.check(((DefaultButtonModel) b3.getModel()).getGroup(), g);
// try null
g.add(null);
harness.check(g.getButtonCount(), 3);
harness.check(g.getSelection(), b2.getModel());