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

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

#28 faster test

File size: 1.6 KB
Line 
1package genius.gui.panels;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import javax.swing.JFrame;
8
9import org.junit.Test;
10
11import genius.core.listener.Listener;
12
13public class SliderPanelTest {
14 @Test
15 public void testPanel() throws InterruptedException {
16 IntegerModel model = new IntegerModel(3, 1, 10, 1);
17 SliderPanel panel = new SliderPanel("test", model);
18
19 JFrame frame = new JFrame();
20 frame.setContentPane(panel);
21 frame.pack();
22 frame.setVisible(true);
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());
29
30 }
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);
55 Thread.sleep(1000);
56 assertEquals((Integer) 2, model.getValue());
57 assertTrue(calledback);
58
59 calledback = false;
60 model.setLock(true);
61 Thread.sleep(1000);
62 assertTrue(calledback);
63 assertFalse(panel.isEnabled());
64
65 calledback = false;
66 model.setLock(false);
67 Thread.sleep(1000);
68 assertTrue(calledback);
69 assertTrue(panel.isEnabled());
70
71 }
72}
Note: See TracBrowser for help on using the repository browser.