source: src/test/java/genius/gui/panels/SliderPanelTest.java@ 127

Last change on this file since 127 was 94, checked in by Wouter Pasman, 6 years ago

#28 faster test

File size: 1.6 KB
RevLine 
[87]1package genius.gui.panels;
2
[88]3import static org.junit.Assert.assertEquals;
[93]4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
[88]6
[87]7import javax.swing.JFrame;
8
9import org.junit.Test;
10
[93]11import genius.core.listener.Listener;
12
[87]13public class SliderPanelTest {
14 @Test
[88]15 public void testPanel() throws InterruptedException {
[91]16 IntegerModel model = new IntegerModel(3, 1, 10, 1);
[87]17 SliderPanel panel = new SliderPanel("test", model);
[88]18
[87]19 JFrame frame = new JFrame();
[88]20 frame.setContentPane(panel);
21 frame.pack();
[87]22 frame.setVisible(true);
[88]23 Thread.sleep(1000);
24 assertEquals((Integer) 3, model.getValue());
25
26 // drag the slider
27 panel.getSlider().setValue(2);
28 assertEquals((Integer) 2, model.getValue());
[93]29
[87]30 }
[93]31
32 private boolean calledback = false;
33
34 @Test
35 public void testPanelEnableDisable() throws InterruptedException {
36 IntegerModel model = new IntegerModel(3, 1, 10, 1);
37 model.addListener(new Listener<Integer>() {
38
39 @Override
40 public void notifyChange(Integer data) {
41 calledback = true;
42 }
43 });
44 SliderPanel panel = new SliderPanel("test", model);
45
46 JFrame frame = new JFrame();
47 frame.setContentPane(panel);
48 frame.pack();
49 frame.setVisible(true);
50 Thread.sleep(1000);
51
52 assertFalse(calledback);
53 // drag the slider
54 panel.getSlider().setValue(2);
[94]55 Thread.sleep(1000);
[93]56 assertEquals((Integer) 2, model.getValue());
57 assertTrue(calledback);
58
59 calledback = false;
60 model.setLock(true);
[94]61 Thread.sleep(1000);
[93]62 assertTrue(calledback);
63 assertFalse(panel.isEnabled());
64
65 calledback = false;
66 model.setLock(false);
[94]67 Thread.sleep(1000);
[93]68 assertTrue(calledback);
69 assertTrue(panel.isEnabled());
70
71 }
[87]72}
Note: See TracBrowser for help on using the repository browser.