001 package org.apache.myfaces.tobago.layout;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 import org.junit.Assert;
021 import org.junit.Test;
022
023 import java.util.Arrays;
024
025 public class MeasureUnitTest {
026
027 private static Measure px(int pixel) {
028 return Measure.valueOf(pixel);
029 }
030
031 @Test
032 public void testMinList() {
033 Assert.assertEquals(px(5), Measure.min(Arrays.asList(px(5), px(10), px(20))));
034 Assert.assertEquals(px(5), Measure.min(Arrays.asList(px(5), null, px(20))));
035 Assert.assertEquals(Measure.MAX, Measure.min(Arrays.asList((Measure) null, null, null)));
036 Assert.assertEquals(Measure.MAX, Measure.min(Arrays.<Measure>asList()));
037 }
038
039 @Test
040 public void testMaxList() {
041 Assert.assertEquals(px(20), Measure.max(Arrays.asList(px(5), px(10), px(20))));
042 Assert.assertEquals(px(20), Measure.max(Arrays.asList(px(5), null, px(20))));
043 Assert.assertEquals(Measure.ZERO, Measure.max(Arrays.asList((Measure) null, null, null)));
044 Assert.assertEquals(Measure.ZERO, Measure.max(Arrays.<Measure>asList()));
045 }
046
047 @Test
048 public void testMin2() {
049 Assert.assertEquals(px(5), Measure.min(px(5), px(10)));
050 Assert.assertEquals(px(10), Measure.min(null, px(10)));
051 Assert.assertEquals(px(5), Measure.min(px(5), null));
052 Assert.assertEquals(Measure.MAX, Measure.min(null, null));
053 }
054
055 @Test
056 public void testMax2() {
057 Assert.assertEquals(px(10), Measure.max(px(5), px(10)));
058 Assert.assertEquals(px(10), Measure.max(null, px(10)));
059 Assert.assertEquals(px(5), Measure.max(px(5), null));
060 Assert.assertEquals(Measure.ZERO, Measure.max(null, null));
061 }
062 }