[1] | 1 | package genius.gui.boaparties;
|
---|
| 2 |
|
---|
| 3 | import static org.mockito.Mockito.mock;
|
---|
| 4 | import static org.mockito.Mockito.when;
|
---|
| 5 |
|
---|
| 6 | import java.awt.BorderLayout;
|
---|
| 7 | import java.util.ArrayList;
|
---|
| 8 | import java.util.Arrays;
|
---|
| 9 | import java.util.List;
|
---|
| 10 |
|
---|
| 11 | import javax.swing.JFrame;
|
---|
| 12 |
|
---|
| 13 | import org.junit.Test;
|
---|
| 14 |
|
---|
| 15 | import genius.core.boaframework.BOAparameter;
|
---|
| 16 | import genius.core.exceptions.InstantiateException;
|
---|
| 17 | import genius.core.repository.RepItem;
|
---|
| 18 | import genius.gui.panels.SingleSelectionModel;
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * bit hacky test. Just opens the panel with a mocked component.
|
---|
| 22 | */
|
---|
| 23 | public class BoaComponentPanelTest {
|
---|
| 24 | @SuppressWarnings("rawtypes")
|
---|
| 25 | @Test
|
---|
| 26 | public void testOpenPanel() throws InstantiateException, InterruptedException {
|
---|
| 27 | JFrame frame = new JFrame();
|
---|
| 28 | frame.setLayout(new BorderLayout());
|
---|
| 29 |
|
---|
| 30 | // Mock a Boa component model to test the GUI
|
---|
| 31 | @SuppressWarnings("rawtypes")
|
---|
| 32 | BoaComponentModel model = mock(BoaComponentModel.class);
|
---|
| 33 | @SuppressWarnings("rawtypes")
|
---|
| 34 | SingleSelectionModel componentlist = mock(SingleSelectionModel.class);
|
---|
| 35 | when(model.getComponentsListModel()).thenReturn(componentlist);
|
---|
| 36 | BoaParametersModel params = mock(BoaParametersModel.class);
|
---|
| 37 | when(model.getParameters()).thenReturn(params);
|
---|
| 38 | when(params.getSetting()).thenReturn(new ArrayList<BOAparameter>());
|
---|
| 39 |
|
---|
| 40 | RepItem comp1 = mock(RepItem.class);
|
---|
| 41 | when(comp1.toString()).thenReturn("comp1");
|
---|
| 42 | RepItem comp2 = mock(RepItem.class);
|
---|
| 43 | when(comp2.toString()).thenReturn("comp2");
|
---|
| 44 | RepItem comp3 = mock(RepItem.class);
|
---|
| 45 | when(comp3.toString()).thenReturn("comp3");
|
---|
| 46 |
|
---|
| 47 | List<RepItem> allitems = Arrays.asList(new RepItem[] { comp1, comp2, comp3 });
|
---|
| 48 | when(componentlist.getAllItems()).thenReturn(allitems);
|
---|
| 49 | when(componentlist.getSelectedItem()).thenReturn(allitems.get(0));
|
---|
| 50 |
|
---|
| 51 | frame.getContentPane().add(new BoaComponentPanel(model, "test boa component panel"), BorderLayout.CENTER);
|
---|
| 52 | frame.pack();
|
---|
| 53 | frame.setVisible(true);
|
---|
| 54 | Thread.sleep(2000);
|
---|
| 55 | frame.setVisible(false);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | }
|
---|