1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.test.swing;
20
21 import java.awt.Dimension;
22 import java.awt.GraphicsEnvironment;
23
24 import net.sourceforge.jeuclid.swing.JMathComponent;
25
26 import org.junit.Assert;
27 import org.junit.Assume;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.w3c.dom.Node;
31
32
33
34
35
36
37 public class JMathComponentTest {
38
39
40 @BeforeClass
41 public static void checkHeadless() {
42 Assume.assumeTrue(!GraphicsEnvironment.isHeadless());
43 }
44
45
46
47
48
49 @Test
50 public void testPreferredSize() {
51 final JMathComponent jmc = new JMathComponent();
52 final Dimension d = jmc.getPreferredSize();
53 Assert.assertEquals(d.getHeight(), 0.0, 0.01);
54 Assert.assertEquals(d.getWidth(), 0.0, 0.01);
55 jmc.setContent("<math><mtext>x</mtext></math>");
56 final Dimension d2 = jmc.getPreferredSize();
57 Assert.assertTrue(d2.getHeight() > 1);
58 Assert.assertTrue(d2.getWidth() > 1);
59 final Node mtext = jmc.getDocument().getFirstChild().getFirstChild();
60 mtext.setTextContent("xxx");
61 final Dimension d3 = jmc.getPreferredSize();
62 Assert.assertEquals(d3.getHeight(), d2.getHeight(), 0.001);
63 Assert.assertTrue(d3.getWidth() > d2.getWidth());
64 }
65 }