View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.layout;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  import java.util.Arrays;
26  
27  public class MeasureUnitTest {
28  
29    private static Measure px(final int pixel) {
30      return Measure.valueOf(pixel);
31    }
32  
33    @Test
34    public void testMinList() {
35      Assert.assertEquals(px(5), Measure.min(Arrays.asList(px(5), px(10), px(20))));
36      Assert.assertEquals(px(5), Measure.min(Arrays.asList(px(5), null, px(20))));
37      Assert.assertEquals(Measure.MAX, Measure.min(Arrays.asList((Measure) null, null, null)));
38      Assert.assertEquals(Measure.MAX, Measure.min(Arrays.<Measure>asList()));
39    }
40  
41    @Test
42    public void testMaxList() {
43      Assert.assertEquals(px(20), Measure.max(Arrays.asList(px(5), px(10), px(20))));
44      Assert.assertEquals(px(20), Measure.max(Arrays.asList(px(5), null, px(20))));
45      Assert.assertEquals(Measure.ZERO, Measure.max(Arrays.asList((Measure) null, null, null)));
46      Assert.assertEquals(Measure.ZERO, Measure.max(Arrays.<Measure>asList()));
47    }
48  
49    @Test
50    public void testMin2() {
51      Assert.assertEquals(px(5), Measure.min(px(5), px(10)));
52      Assert.assertEquals(px(10), Measure.min(null, px(10)));
53      Assert.assertEquals(px(5), Measure.min(px(5), null));
54      Assert.assertEquals(Measure.MAX, Measure.min(null, null));
55    }
56  
57    @Test
58    public void testMax2() {
59      Assert.assertEquals(px(10), Measure.max(px(5), px(10)));
60      Assert.assertEquals(px(10), Measure.max(null, px(10)));
61      Assert.assertEquals(px(5), Measure.max(px(5), null));
62      Assert.assertEquals(Measure.ZERO, Measure.max(null, null));
63    }
64  
65    @Test
66    public void testDecimal() {
67      Assert.assertEquals(Measure.valueOf("13.3px"), px(13));
68      Assert.assertEquals(Measure.valueOf("13.7px"), px(13));
69      Assert.assertEquals(Measure.valueOf("13.3"), px(13));
70      Assert.assertEquals(Measure.valueOf("13.7"), px(13));
71      Assert.assertEquals(Measure.valueOf(".7"), px(0));
72    }
73  }