public class show implements Testlet
{
public void test(TestHarness harness)
{
CardLayout layout = new CardLayout();
Frame containerWithLayout = new Frame();
Panel panel = new Panel();
containerWithLayout.setLayout(layout);
containerWithLayout.add(panel, "Panel");
// test correct usage
try
{
layout.show(containerWithLayout, "Panel");
harness.check(true);
}
catch (Exception e)
{
harness.check(false);
}
// test with string == null
// nothing should happen no exception
try
{
layout.show(containerWithLayout, null);
harness.check(true);
}
catch (Exception e)
{
e.printStackTrace();
harness.check(false);
}
// same with unknown names
try
{
layout.show(containerWithLayout, "XXXXX");
harness.check(true);
}
catch (Exception e)
{
harness.check(false);
}
// same with empty strings
try
{
layout.show(containerWithLayout, "");
harness.check(true);
}
catch (Exception e)
{
harness.check(false);
}
// test usage with container without setLayout called
Frame container = new Frame();
container.add(panel);
try
{
layout.show(container, "Panel");
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// test usage with container with another CardLayout instance called
CardLayout layout2 = new CardLayout();
container.setLayout(layout2);
try
{
layout.show(container, "Panel");
harness.check(false);