JAL-4274 comments to help follow the tests
[jalview.git] / test / jalview / util / ImageMakerTest.java
1 package jalview.util;
2
3 import org.testng.Assert;
4 import org.testng.annotations.Test;
5
6 import jalview.bin.Cache;
7 import jalview.util.imagemaker.BitmapImageSizing;
8
9 public class ImageMakerTest
10 {
11   @Test(groups = { "Functional" })
12   public void testParseScaleWidthHeightStrings()
13   {
14     Cache.setPropsAreReadOnly(true);
15     Cache.loadProperties("test/jalview/bin/testProps.jvprops");
16
17     Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE);
18     Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT);
19     Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
20
21     BitmapImageSizing bis = null;
22
23     // No defaults set, 3 values given. Should be the 3 values.
24     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
25     Assert.assertEquals(bis.scale(), 1.2f,
26             "scale not parsed and set to value given");
27     Assert.assertEquals(bis.width(), 3,
28             "width not parsed and set to value given");
29     Assert.assertEquals(bis.height(), 4,
30             "height not parsed and set to value given");
31
32     // No defaults set, 1 value given. Should be the 1 value and 2 0s.
33     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
34     Assert.assertEquals(bis.scale(), 1.2f,
35             "scale not parsed and set to value given");
36     Assert.assertEquals(bis.width(), 0, "width not parsed and set to 0");
37     Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
38
39     // No defaults set, 1 value given. Should be the 1 value and 2 0s. (checking
40     // the other value)
41     bis = ImageMaker.parseScaleWidthHeightStrings(null, "1", null);
42     Assert.assertEquals(bis.scale(), 0f, "scale not parsed and set to 0f");
43     Assert.assertEquals(bis.width(), 1,
44             "width not parsed and set to value given");
45     Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
46
47     // No defaults set, no values given, these should first look at defaults and
48     // then set all to 0
49     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
50     Assert.assertEquals(bis.scale(), 0f,
51             "scale not parsed and set to undefined default 0f");
52     Assert.assertEquals(bis.width(), 0,
53             "width not parsed and set to undefined default 0");
54     Assert.assertEquals(bis.height(), 0,
55             "height not parsed and set to undefined default 0");
56
57     Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "1");
58     // 1 default set, bis should detect this
59     Assert.assertEquals(bis.scale(), 0f,
60             "scale not parsed and set to undefined default 0f");
61     Assert.assertEquals(bis.width(), 0,
62             "width not parsed and set to undefined default 0");
63     Assert.assertEquals(bis.height(), 1,
64             "height not parsed and set to default 1");
65
66     Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "3.4");
67     Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "2");
68     // Now all 3 defaults set, bis should detect this
69     Assert.assertEquals(bis.scale(), 3.4f,
70             "scale not parsed and set to undefined default 3.2f");
71     Assert.assertEquals(bis.width(), 2,
72             "width not parsed and set to undefined default 2");
73     Assert.assertEquals(bis.height(), 1,
74             "height not parsed and set to default 1");
75
76     // 3 defaults set, and 3 values given, should use the 3 values
77     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
78     Assert.assertEquals(bis.scale(), 1.2f,
79             "scale not parsed and set to value given");
80     Assert.assertEquals(bis.width(), 3,
81             "width not parsed and set to value given");
82     Assert.assertEquals(bis.height(), 4,
83             "height not parsed and set to value given");
84
85     // 3 defaults set, and 1 value given, should use the 1 value and 2 0s
86     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
87     Assert.assertEquals(bis.scale(), 1.2f,
88             "scale not parsed and set to value given");
89     Assert.assertEquals(bis.width(), 0,
90             "width not parsed and set to undefined 0");
91     Assert.assertEquals(bis.height(), 0,
92             "height not parsed and set to undefined 0");
93
94     // 3 defaults set, and 1 value given, should use the 1 value and 2 0s
95     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, "5");
96     Assert.assertEquals(bis.scale(), 0f,
97             "scale not parsed and set to undefined 0f");
98     Assert.assertEquals(bis.width(), 0,
99             "width not parsed and set to undefined 0");
100     Assert.assertEquals(bis.height(), 5,
101             "height not parsed and set to value given");
102
103     // 3 defaults set, and no values given, should use the 3 default values
104     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
105     Assert.assertEquals(bis.scale(), 3.4f,
106             "scale not parsed and set to undefined default 3.2f");
107     Assert.assertEquals(bis.width(), 2,
108             "width not parsed and set to undefined default 2");
109     Assert.assertEquals(bis.height(), 1,
110             "height not parsed and set to default 1");
111   }
112 }