Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java Tue Oct 31 19:15:47 2023 @@ -1,32 +1,32 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.validation; - -import java.math.BigDecimal; -import java.util.Locale; - -/** - * A validator for a BigDecimal value. - */ -public class BigDecimalValidator extends ComparableValidator<BigDecimal> { - - public BigDecimalValidator() { - super(); - } - - public BigDecimalValidator(Locale locale) { - super(locale); - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.validation; + +import java.math.BigDecimal; +import java.util.Locale; + +/** + * A validator for a BigDecimal value. + */ +public class BigDecimalValidator extends ComparableValidator<BigDecimal> { + + public BigDecimalValidator() { + super(); + } + + public BigDecimalValidator(Locale locale) { + super(locale); + } + +}
Propchange: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java Tue Oct 31 19:15:47 2023 @@ -1,32 +1,32 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.validation; - -import java.math.BigInteger; -import java.util.Locale; - -/** - * A validator for a BigInteger value. - */ -public class BigIntegerValidator extends ComparableValidator<BigInteger> { - - public BigIntegerValidator() { - super(); - } - - public BigIntegerValidator(Locale locale) { - super(locale); - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.validation; + +import java.math.BigInteger; +import java.util.Locale; + +/** + * A validator for a BigInteger value. + */ +public class BigIntegerValidator extends ComparableValidator<BigInteger> { + + public BigIntegerValidator() { + super(); + } + + public BigIntegerValidator(Locale locale) { + super(locale); + } + +} Propchange: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java Tue Oct 31 19:15:47 2023 @@ -1,89 +1,89 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.validation; - -import java.util.Locale; - -import org.apache.pivot.util.Utils; - -/** - * Generic validator version for a Comparable value limited in a range. - */ -public class ComparableRangeValidator<T extends Comparable<T>> extends ComparableValidator<T> { - private T minValue; - private T maxValue; - - public ComparableRangeValidator() { - this(Locale.getDefault()); - } - - public ComparableRangeValidator(Locale locale) { - super(locale); - this.minValue = null; - this.maxValue = null; - } - - public ComparableRangeValidator(T minValue, T maxValue) { - this(Locale.getDefault(), minValue, maxValue); - } - - public ComparableRangeValidator(Locale locale, T minValue, T maxValue) { - super(locale); - setMinimum(minValue); - setMaximum(maxValue); - - if (maxValue.compareTo(minValue) < 0) { - throw new IllegalArgumentException("maxValue must be higher or equals than minValue"); - } - } - - public T getMinimum() { - return minValue; - } - - public void setMinimum(T minValue) { - Utils.checkNull(minValue, "minValue"); - this.minValue = minValue; - } - - public T getMaximum() { - return maxValue; - } - - public void setMaximum(T maxValue) { - Utils.checkNull(maxValue, "maxValue"); - this.maxValue = maxValue; - } - - @Override - public boolean isValid(String text) { - boolean valid = false; - - if (super.isValid(text)) { - @SuppressWarnings("unchecked") - final Comparable<T> value = (Comparable<T>) textToComparable(text); - if (value != null) { - valid = (value.compareTo(minValue) >= 0 && value.compareTo(maxValue) <= 0); - } - } - - return valid; - } - - @Override - public String toString() { - return (this.getClass().getSimpleName() + "(" + minValue + "," + maxValue + ")"); - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.validation; + +import java.util.Locale; + +import org.apache.pivot.util.Utils; + +/** + * Generic validator version for a Comparable value limited in a range. + */ +public class ComparableRangeValidator<T extends Comparable<T>> extends ComparableValidator<T> { + private T minValue; + private T maxValue; + + public ComparableRangeValidator() { + this(Locale.getDefault()); + } + + public ComparableRangeValidator(Locale locale) { + super(locale); + this.minValue = null; + this.maxValue = null; + } + + public ComparableRangeValidator(T minValue, T maxValue) { + this(Locale.getDefault(), minValue, maxValue); + } + + public ComparableRangeValidator(Locale locale, T minValue, T maxValue) { + super(locale); + setMinimum(minValue); + setMaximum(maxValue); + + if (maxValue.compareTo(minValue) < 0) { + throw new IllegalArgumentException("maxValue must be higher or equals than minValue"); + } + } + + public T getMinimum() { + return minValue; + } + + public void setMinimum(T minValue) { + Utils.checkNull(minValue, "minValue"); + this.minValue = minValue; + } + + public T getMaximum() { + return maxValue; + } + + public void setMaximum(T maxValue) { + Utils.checkNull(maxValue, "maxValue"); + this.maxValue = maxValue; + } + + @Override + public boolean isValid(String text) { + boolean valid = false; + + if (super.isValid(text)) { + @SuppressWarnings("unchecked") + final Comparable<T> value = (Comparable<T>) textToComparable(text); + if (value != null) { + valid = (value.compareTo(minValue) >= 0 && value.compareTo(maxValue) <= 0); + } + } + + return valid; + } + + @Override + public String toString() { + return (this.getClass().getSimpleName() + "(" + minValue + "," + maxValue + ")"); + } + +} Propchange: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java Tue Oct 31 19:15:47 2023 @@ -1,48 +1,48 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.validation; - -import java.util.Locale; - -/** - * A validator for a Comparable value. - */ -public class ComparableValidator<T extends Comparable<T>> extends DecimalValidator { - - public ComparableValidator() { - super(); - } - - public ComparableValidator(Locale locale) { - super(locale); - } - - @Override - public boolean isValid(String text) { - boolean valid = false; - - if (super.isValid(text)) { - @SuppressWarnings("unchecked") - final Comparable<T> value = (Comparable<T>) textToComparable(text); - valid = (value != null); - } - - return valid; - } - - protected final Comparable<?> textToComparable(String text) { - return textToBigDecimal(text); - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.validation; + +import java.util.Locale; + +/** + * A validator for a Comparable value. + */ +public class ComparableValidator<T extends Comparable<T>> extends DecimalValidator { + + public ComparableValidator() { + super(); + } + + public ComparableValidator(Locale locale) { + super(locale); + } + + @Override + public boolean isValid(String text) { + boolean valid = false; + + if (super.isValid(text)) { + @SuppressWarnings("unchecked") + final Comparable<T> value = (Comparable<T>) textToComparable(text); + valid = (value != null); + } + + return valid; + } + + protected final Comparable<?> textToComparable(String text) { + return textToBigDecimal(text); + } + +} Propchange: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java Tue Oct 31 19:15:47 2023 @@ -1,30 +1,30 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.validation; - -/** - * A validator for a (trimmed) text. <p> This is useful only when a value to be - * valid has to be absent. - */ -public class EmptyTextValidator implements Validator { - - public EmptyTextValidator() { - } - - @Override - public boolean isValid(String text) { - return (text.trim()).length() == 0; - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.validation; + +/** + * A validator for a (trimmed) text. <p> This is useful only when a value to be + * valid has to be absent. + */ +public class EmptyTextValidator implements Validator { + + public EmptyTextValidator() { + } + + @Override + public boolean isValid(String text) { + return (text.trim()).length() == 0; + } + +} Propchange: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/LongRangeValidator.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/LongRangeValidator.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/LongRangeValidator.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/LongRangeValidator.java Tue Oct 31 19:15:47 2023 @@ -1,81 +1,81 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.validation; - -import java.math.BigInteger; -import java.util.Locale; - -/** - * A validator for a {@code long} value limited to a range. - * <p> {@link BigInteger} math is used here so that proper checks against - * the limits of the type can be done. - * - * @see ComparableRangeValidator - */ -public class LongRangeValidator extends IntValidator { - private long minValue, maxValue; - - public LongRangeValidator() { - this.minValue = Long.MIN_VALUE; - this.maxValue = Long.MAX_VALUE; - } - - public LongRangeValidator(Locale locale) { - super(locale); - this.minValue = Long.MIN_VALUE; - this.maxValue = Long.MAX_VALUE; - } - - public LongRangeValidator(long minValue, long maxValue) { - this.minValue = minValue; - this.maxValue = maxValue; - } - - public LongRangeValidator(Locale locale, long minValue, long maxValue) { - super(locale); - this.minValue = minValue; - this.maxValue = maxValue; - } - - public long getMinimum() { - return minValue; - } - - public void setMinimum(long minValue) { - this.minValue = minValue; - } - - public long getMaximum() { - return maxValue; - } - - public void setMaximum(long maxValue) { - this.maxValue = maxValue; - } - - @Override - public boolean isValid(String text) { - boolean valid = false; - - if (super.isValid(text)) { - BigInteger min = BigInteger.valueOf(minValue); - BigInteger max = BigInteger.valueOf(maxValue); - BigInteger value = new BigInteger(text); - valid = value.compareTo(min) >= 0 && value.compareTo(max) <= 0; - } - - return valid; - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.validation; + +import java.math.BigInteger; +import java.util.Locale; + +/** + * A validator for a {@code long} value limited to a range. + * <p> {@link BigInteger} math is used here so that proper checks against + * the limits of the type can be done. + * + * @see ComparableRangeValidator + */ +public class LongRangeValidator extends IntValidator { + private long minValue, maxValue; + + public LongRangeValidator() { + this.minValue = Long.MIN_VALUE; + this.maxValue = Long.MAX_VALUE; + } + + public LongRangeValidator(Locale locale) { + super(locale); + this.minValue = Long.MIN_VALUE; + this.maxValue = Long.MAX_VALUE; + } + + public LongRangeValidator(long minValue, long maxValue) { + this.minValue = minValue; + this.maxValue = maxValue; + } + + public LongRangeValidator(Locale locale, long minValue, long maxValue) { + super(locale); + this.minValue = minValue; + this.maxValue = maxValue; + } + + public long getMinimum() { + return minValue; + } + + public void setMinimum(long minValue) { + this.minValue = minValue; + } + + public long getMaximum() { + return maxValue; + } + + public void setMaximum(long maxValue) { + this.maxValue = maxValue; + } + + @Override + public boolean isValid(String text) { + boolean valid = false; + + if (super.isValid(text)) { + BigInteger min = BigInteger.valueOf(minValue); + BigInteger max = BigInteger.valueOf(maxValue); + BigInteger value = new BigInteger(text); + valid = value.compareTo(min) >= 0 && value.compareTo(max) <= 0; + } + + return valid; + } + +} Propchange: pivot/trunk/wtk/src/org/apache/pivot/wtk/validation/LongRangeValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BoundsTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BoundsTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BoundsTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BoundsTest.java Tue Oct 31 19:15:47 2023 @@ -1,103 +1,103 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import org.apache.pivot.wtk.Bounds; -import org.apache.pivot.wtk.Dimensions; -import org.apache.pivot.wtk.Point; - - -/** - * Tests the {@link Bounds} class which is used extensively - * in the "wtk" source, and deserves good tests. - */ -public class BoundsTest { - - @Test - public void test() { - Bounds bndMinus1 = new Bounds(-1, -1, 0, 0); - Bounds bnd0 = new Bounds(0, 0, 0, 0); - Bounds bnd1 = new Bounds(1, 1, 1, 1); - - Dimensions dim0 = new Dimensions(0, 0); - Dimensions dim1 = new Dimensions(1, 1); - Dimensions dim5 = new Dimensions(5); - Point p10 = new Point(10, 10); - Bounds bnd10 = new Bounds(p10, dim1); - Bounds bnd10a = new Bounds(dim1); - Bounds bnd10b = new Bounds(0, 0, 1, 1); - - Bounds bnd2 = Bounds.decode("[2, 3, 4, 5]"); - Bounds bnd3 = Bounds.decode("{x:2, y:3, width:4, height:5}"); - Bounds bnd3a = new Bounds(2, 3, 4, 5); - - Bounds bnd4 = new Bounds(4, 4, 4, 5); - Bounds bnd5 = bnd3a.translate(1, 1); // -> {3, 4, 4, 5} - bnd5 = bnd5.expand(-2, -4); - Bounds bnd5a = new Bounds(3, 4, 2, 1); - Bounds bnd5b = new Bounds(4, 3, 1, 2); - Bounds bndN = new Bounds(0, 0, 8, 9); - Bounds bndAll = bnd1.union(bnd0).union(bnd2).union(bnd3).union(bnd4); - - Bounds bnd6 = Bounds.decode("2, 3; 4, 5"); - Bounds bnd6a = new Bounds(2, 3, 4, 5); - - Bounds bnd7 = bnd6a.enlarge(2); - Bounds bnd7a = bnd6a.enlarge(1, 3); - - assertEquals(Bounds.EMPTY, bnd0); - assertNotEquals(bndMinus1, bnd0); - assertNotEquals(bnd0, bnd1); - assertEquals(bnd10a, bnd10b); - - assertEquals(bnd10.getLocation(), p10); - assertEquals(bnd10.getSize(), dim1); - assertEquals(bnd2, bnd3); - assertEquals(bnd3, bnd3a); - - assertEquals(dim0, bndMinus1.getSize()); - assertEquals(dim0, bnd0.getSize()); - assertEquals(dim1, bnd1.getSize()); - - assertFalse(bnd1.contains(bnd0)); - - assertFalse(bndMinus1.intersects(bnd0)); - assertFalse(bnd0.intersects(bnd1)); - assertEquals(new Bounds(1, 1, -1, -1), bnd0.intersect(bnd1)); - assertTrue(bnd5a.intersects(bnd5b)); - assertTrue(bnd0.union(bnd1).equals(new Bounds(0, 0, 2, 2))); - - assertFalse(bnd0.equals(bnd1)); - - assertTrue(bnd5.equals(bnd5a)); - assertEquals(bndN, bndAll); - - assertEquals(bnd6, bnd6a); - assertEquals("Bounds [2,3;4x5]", bnd6a.toString()); - - assertEquals("Bounds [0,1;8x9]", bnd7.toString()); - assertEquals("Bounds [1,0;6x11]", bnd7a.toString()); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.apache.pivot.wtk.Bounds; +import org.apache.pivot.wtk.Dimensions; +import org.apache.pivot.wtk.Point; + + +/** + * Tests the {@link Bounds} class which is used extensively + * in the "wtk" source, and deserves good tests. + */ +public class BoundsTest { + + @Test + public void test() { + Bounds bndMinus1 = new Bounds(-1, -1, 0, 0); + Bounds bnd0 = new Bounds(0, 0, 0, 0); + Bounds bnd1 = new Bounds(1, 1, 1, 1); + + Dimensions dim0 = new Dimensions(0, 0); + Dimensions dim1 = new Dimensions(1, 1); + Dimensions dim5 = new Dimensions(5); + Point p10 = new Point(10, 10); + Bounds bnd10 = new Bounds(p10, dim1); + Bounds bnd10a = new Bounds(dim1); + Bounds bnd10b = new Bounds(0, 0, 1, 1); + + Bounds bnd2 = Bounds.decode("[2, 3, 4, 5]"); + Bounds bnd3 = Bounds.decode("{x:2, y:3, width:4, height:5}"); + Bounds bnd3a = new Bounds(2, 3, 4, 5); + + Bounds bnd4 = new Bounds(4, 4, 4, 5); + Bounds bnd5 = bnd3a.translate(1, 1); // -> {3, 4, 4, 5} + bnd5 = bnd5.expand(-2, -4); + Bounds bnd5a = new Bounds(3, 4, 2, 1); + Bounds bnd5b = new Bounds(4, 3, 1, 2); + Bounds bndN = new Bounds(0, 0, 8, 9); + Bounds bndAll = bnd1.union(bnd0).union(bnd2).union(bnd3).union(bnd4); + + Bounds bnd6 = Bounds.decode("2, 3; 4, 5"); + Bounds bnd6a = new Bounds(2, 3, 4, 5); + + Bounds bnd7 = bnd6a.enlarge(2); + Bounds bnd7a = bnd6a.enlarge(1, 3); + + assertEquals(Bounds.EMPTY, bnd0); + assertNotEquals(bndMinus1, bnd0); + assertNotEquals(bnd0, bnd1); + assertEquals(bnd10a, bnd10b); + + assertEquals(bnd10.getLocation(), p10); + assertEquals(bnd10.getSize(), dim1); + assertEquals(bnd2, bnd3); + assertEquals(bnd3, bnd3a); + + assertEquals(dim0, bndMinus1.getSize()); + assertEquals(dim0, bnd0.getSize()); + assertEquals(dim1, bnd1.getSize()); + + assertFalse(bnd1.contains(bnd0)); + + assertFalse(bndMinus1.intersects(bnd0)); + assertFalse(bnd0.intersects(bnd1)); + assertEquals(new Bounds(1, 1, -1, -1), bnd0.intersect(bnd1)); + assertTrue(bnd5a.intersects(bnd5b)); + assertTrue(bnd0.union(bnd1).equals(new Bounds(0, 0, 2, 2))); + + assertFalse(bnd0.equals(bnd1)); + + assertTrue(bnd5.equals(bnd5a)); + assertEquals(bndN, bndAll); + + assertEquals(bnd6, bnd6a); + assertEquals("Bounds [2,3;4x5]", bnd6a.toString()); + + assertEquals("Bounds [0,1;8x9]", bnd7.toString()); + assertEquals("Bounds [1,0;6x11]", bnd7a.toString()); + } + +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/BoundsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java Tue Oct 31 19:15:47 2023 @@ -1,122 +1,122 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import java.awt.Color; -import java.lang.reflect.Field; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import org.apache.pivot.util.ClassUtils; -import org.apache.pivot.wtk.CSSColor; -import org.apache.pivot.wtk.GraphicsUtilities; -import org.apache.pivot.wtk.util.ColorUtilities; - - -/** - * Tests the {@link CSSColor} enum and various {@link ColorUtilities} methods. - */ -public class CSSColorTest { - private void testColors(final CSSColor original, final CSSColor lookup) { - // Doing an exact match here is problematic because many of the - // CSS colors have duplicate color values, even synonyms - // (vis. DarkGray and DarkGrey), so do some clever checking. - if (original != lookup) { - if (!original.getColor().equals(lookup.getColor())) { - String message = String.format("CSS Color %1$s (%2$s) gets wrong color by lookup %3$s (%4$s)!", - original, ClassUtils.defaultToString(original), - lookup, ClassUtils.defaultToString(lookup)); - fail(message); - } else { - // Log the "failures" for the record - String message = String.format("Note: CSS Color %1$s matches %2$s by color (%3$s), but not by value.", - original, lookup, lookup.getColor()); - System.out.println(message); - } - } - } - - @Test - public void test() { - // We're going to do a full round-trip cycle to test everything - for (CSSColor css : CSSColor.values()) { - Color underlyingColor = css.getColor(); - String name = css.getColorName(); - CSSColor lookupByName = CSSColor.fromString(name); - assertEquals(css, lookupByName); - - CSSColor lookupByColor = CSSColor.fromColor(underlyingColor); - testColors(css, lookupByColor); - - String stringValue = ColorUtilities.toStringValue(css); - Color decodedColor = GraphicsUtilities.decodeColor(stringValue, name); - CSSColor lookupByDecodedValue = CSSColor.fromColor(decodedColor); - testColors(css, lookupByDecodedValue); - - String enumName = ((Object) css).toString(); - CSSColor lookupByEnumName = CSSColor.fromString(enumName); - assertEquals(css, lookupByEnumName); - } - } - - @Test - public void test2() throws IllegalAccessException { - // Now, test to make sure the CSS and regular Java colors work "right". - for (Field f : Color.class.getDeclaredFields()) { - Class<?> clazz = f.getType(); - if (clazz.equals(Color.class)) { - String javaColorName = f.getName(); - CSSColor cssEquivalent = CSSColor.fromString(javaColorName); - assertEquals(f.getName() + " does not match in CSSColor lookup", - cssEquivalent.getColor(), (Color) f.get(null)); - } - } - } - - @Test - public void test3() { - Set<CSSColor> matchingColors = CSSColor.getMatchingColors(Color.black); - assertEquals(3, matchingColors.size()); - assertTrue(matchingColors.contains(CSSColor.black)); - assertTrue(matchingColors.contains(CSSColor.BLACK)); - assertTrue(matchingColors.contains(CSSColor.Black)); - - Set<CSSColor> match2 = CSSColor.getMatchingColors(Color.GREEN); - assertEquals(3, match2.size()); - assertTrue(match2.contains(CSSColor.green)); - assertTrue(match2.contains(CSSColor.GREEN)); - assertTrue(match2.contains(CSSColor.Lime)); - assertFalse(match2.contains(CSSColor.Green)); - - Set<CSSColor> match3 = CSSColor.getMatchingColors(CSSColor.SandyBrown.getColor()); - assertEquals(1, match3.size()); - assertTrue(match3.contains(CSSColor.SandyBrown)); - - Set<CSSColor> match4 = CSSColor.getMatchingColors(new Color(255, 239, 213)); - assertEquals(1, match4.size()); - assertTrue(match4.contains(CSSColor.PapayaWhip)); - - Set<CSSColor> matchEmpty = CSSColor.getMatchingColors(new Color(3, 3, 3)); - assertEquals(0, matchEmpty.size()); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import java.awt.Color; +import java.lang.reflect.Field; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import org.apache.pivot.util.ClassUtils; +import org.apache.pivot.wtk.CSSColor; +import org.apache.pivot.wtk.GraphicsUtilities; +import org.apache.pivot.wtk.util.ColorUtilities; + + +/** + * Tests the {@link CSSColor} enum and various {@link ColorUtilities} methods. + */ +public class CSSColorTest { + private void testColors(final CSSColor original, final CSSColor lookup) { + // Doing an exact match here is problematic because many of the + // CSS colors have duplicate color values, even synonyms + // (vis. DarkGray and DarkGrey), so do some clever checking. + if (original != lookup) { + if (!original.getColor().equals(lookup.getColor())) { + String message = String.format("CSS Color %1$s (%2$s) gets wrong color by lookup %3$s (%4$s)!", + original, ClassUtils.defaultToString(original), + lookup, ClassUtils.defaultToString(lookup)); + fail(message); + } else { + // Log the "failures" for the record + String message = String.format("Note: CSS Color %1$s matches %2$s by color (%3$s), but not by value.", + original, lookup, lookup.getColor()); + System.out.println(message); + } + } + } + + @Test + public void test() { + // We're going to do a full round-trip cycle to test everything + for (CSSColor css : CSSColor.values()) { + Color underlyingColor = css.getColor(); + String name = css.getColorName(); + CSSColor lookupByName = CSSColor.fromString(name); + assertEquals(css, lookupByName); + + CSSColor lookupByColor = CSSColor.fromColor(underlyingColor); + testColors(css, lookupByColor); + + String stringValue = ColorUtilities.toStringValue(css); + Color decodedColor = GraphicsUtilities.decodeColor(stringValue, name); + CSSColor lookupByDecodedValue = CSSColor.fromColor(decodedColor); + testColors(css, lookupByDecodedValue); + + String enumName = ((Object) css).toString(); + CSSColor lookupByEnumName = CSSColor.fromString(enumName); + assertEquals(css, lookupByEnumName); + } + } + + @Test + public void test2() throws IllegalAccessException { + // Now, test to make sure the CSS and regular Java colors work "right". + for (Field f : Color.class.getDeclaredFields()) { + Class<?> clazz = f.getType(); + if (clazz.equals(Color.class)) { + String javaColorName = f.getName(); + CSSColor cssEquivalent = CSSColor.fromString(javaColorName); + assertEquals(f.getName() + " does not match in CSSColor lookup", + cssEquivalent.getColor(), (Color) f.get(null)); + } + } + } + + @Test + public void test3() { + Set<CSSColor> matchingColors = CSSColor.getMatchingColors(Color.black); + assertEquals(3, matchingColors.size()); + assertTrue(matchingColors.contains(CSSColor.black)); + assertTrue(matchingColors.contains(CSSColor.BLACK)); + assertTrue(matchingColors.contains(CSSColor.Black)); + + Set<CSSColor> match2 = CSSColor.getMatchingColors(Color.GREEN); + assertEquals(3, match2.size()); + assertTrue(match2.contains(CSSColor.green)); + assertTrue(match2.contains(CSSColor.GREEN)); + assertTrue(match2.contains(CSSColor.Lime)); + assertFalse(match2.contains(CSSColor.Green)); + + Set<CSSColor> match3 = CSSColor.getMatchingColors(CSSColor.SandyBrown.getColor()); + assertEquals(1, match3.size()); + assertTrue(match3.contains(CSSColor.SandyBrown)); + + Set<CSSColor> match4 = CSSColor.getMatchingColors(new Color(255, 239, 213)); + assertEquals(1, match4.size()); + assertTrue(match4.contains(CSSColor.PapayaWhip)); + + Set<CSSColor> matchEmpty = CSSColor.getMatchingColors(new Color(3, 3, 3)); + assertEquals(0, matchEmpty.size()); + } +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ColorUtilitiesTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ColorUtilitiesTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ColorUtilitiesTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ColorUtilitiesTest.java Tue Oct 31 19:15:47 2023 @@ -1,111 +1,111 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import java.awt.Color; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import org.apache.pivot.wtk.CSSColor; -import org.apache.pivot.wtk.GraphicsUtilities; -import org.apache.pivot.wtk.util.ColorUtilities; - - -/** - * Tests the {@link ColorUtilities} class methods. - */ -public class ColorUtilitiesTest { - @Test - public void test1() { - Color black = CSSColor.Black.getColor(); - String sBlack = ColorUtilities.toStringValue(black); - assertEquals(sBlack, "#000000"); - - Color red = Color.RED; - String sRed = ColorUtilities.toStringValue(red); - assertEquals(sRed, "#FF0000"); - - Color almostBlack = new Color(1, 1, 1); - try { - CSSColor almostBlackColor = CSSColor.fromColor(almostBlack); - fail("almostBlack should not be a CSS color!"); - } catch (IllegalArgumentException iae) { - System.out.println("Valid exception: " + iae.getMessage()); - assertEquals(iae.getMessage(), "Incorrect Color value. " - + almostBlack.toString() + " does not match any CSS color."); - } - - Color translucentOrange = ColorUtilities.toTransparentColor(CSSColor.ORANGE, 128); - assertEquals(ColorUtilities.toStringValue(translucentOrange), "0xFFC80080"); - try { - CSSColor resultOrange = CSSColor.fromColor(translucentOrange); - assertEquals(resultOrange.getColor(), Color.ORANGE); - } catch (IllegalArgumentException iae) { - fail("Didn't expect ORANGE not to match!"); - } - - // Make sure some of the weirder Java colors work right - Color lightGray = Color.LIGHT_GRAY; - Color darkGray = Color.DARK_GRAY; - assertEquals(lightGray, CSSColor.LIGHT_GRAY.getColor()); - assertEquals(lightGray, CSSColor.lightGray.getColor()); - assertEquals(darkGray, CSSColor.DARK_GRAY.getColor()); - assertEquals(darkGray, CSSColor.darkGray.getColor()); - CSSColor lightGrey = CSSColor.fromString("lightGray"); - assertEquals(lightGrey.getColor(), lightGray); - - // Now, highlight some of the differences between CSS and Java colors with similar names - Color javaGreen = Color.green; - assertEquals(javaGreen, Color.GREEN); - assertNotSame(javaGreen, CSSColor.Green.getColor()); - assertNotSame(lightGray, CSSColor.LightGrey.getColor()); - assertNotSame(Color.orange, CSSColor.Orange.getColor()); - assertNotSame(Color.PINK, CSSColor.Pink.getColor()); - - // And test that some of the CSS and Java colors have the same values and different names - assertEquals(Color.cyan, CSSColor.Aqua.getColor()); - assertEquals(Color.GREEN, CSSColor.Lime.getColor()); - - try { - Color lg2 = GraphicsUtilities.decodeColor("lightGray"); - assertEquals(lg2, lightGray); - } catch (IllegalArgumentException iae) { - fail("Decode of \"lightGray\" should succeed!"); - } - - assertEquals((Color) null, GraphicsUtilities.decodeColor("null")); - - int transparency = -1; - for (CSSColor color : CSSColor.values()) { - transparency = (transparency + 1) % 256; - Color originalColor = color.getColor(); - Color translucentColor = ColorUtilities.toTransparentColor(color, transparency); - String value = (transparency == 255) - ? String.format("#%02X%02X%02X", - originalColor.getRed(), originalColor.getGreen(), originalColor.getBlue()) - : String.format("0x%02X%02X%02X%02X", - originalColor.getRed(), originalColor.getGreen(), originalColor.getBlue(), transparency); - String testValue = ColorUtilities.toStringValue(translucentColor); - assertEquals(value, testValue); - } - - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import java.awt.Color; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import org.apache.pivot.wtk.CSSColor; +import org.apache.pivot.wtk.GraphicsUtilities; +import org.apache.pivot.wtk.util.ColorUtilities; + + +/** + * Tests the {@link ColorUtilities} class methods. + */ +public class ColorUtilitiesTest { + @Test + public void test1() { + Color black = CSSColor.Black.getColor(); + String sBlack = ColorUtilities.toStringValue(black); + assertEquals(sBlack, "#000000"); + + Color red = Color.RED; + String sRed = ColorUtilities.toStringValue(red); + assertEquals(sRed, "#FF0000"); + + Color almostBlack = new Color(1, 1, 1); + try { + CSSColor almostBlackColor = CSSColor.fromColor(almostBlack); + fail("almostBlack should not be a CSS color!"); + } catch (IllegalArgumentException iae) { + System.out.println("Valid exception: " + iae.getMessage()); + assertEquals(iae.getMessage(), "Incorrect Color value. " + + almostBlack.toString() + " does not match any CSS color."); + } + + Color translucentOrange = ColorUtilities.toTransparentColor(CSSColor.ORANGE, 128); + assertEquals(ColorUtilities.toStringValue(translucentOrange), "0xFFC80080"); + try { + CSSColor resultOrange = CSSColor.fromColor(translucentOrange); + assertEquals(resultOrange.getColor(), Color.ORANGE); + } catch (IllegalArgumentException iae) { + fail("Didn't expect ORANGE not to match!"); + } + + // Make sure some of the weirder Java colors work right + Color lightGray = Color.LIGHT_GRAY; + Color darkGray = Color.DARK_GRAY; + assertEquals(lightGray, CSSColor.LIGHT_GRAY.getColor()); + assertEquals(lightGray, CSSColor.lightGray.getColor()); + assertEquals(darkGray, CSSColor.DARK_GRAY.getColor()); + assertEquals(darkGray, CSSColor.darkGray.getColor()); + CSSColor lightGrey = CSSColor.fromString("lightGray"); + assertEquals(lightGrey.getColor(), lightGray); + + // Now, highlight some of the differences between CSS and Java colors with similar names + Color javaGreen = Color.green; + assertEquals(javaGreen, Color.GREEN); + assertNotSame(javaGreen, CSSColor.Green.getColor()); + assertNotSame(lightGray, CSSColor.LightGrey.getColor()); + assertNotSame(Color.orange, CSSColor.Orange.getColor()); + assertNotSame(Color.PINK, CSSColor.Pink.getColor()); + + // And test that some of the CSS and Java colors have the same values and different names + assertEquals(Color.cyan, CSSColor.Aqua.getColor()); + assertEquals(Color.GREEN, CSSColor.Lime.getColor()); + + try { + Color lg2 = GraphicsUtilities.decodeColor("lightGray"); + assertEquals(lg2, lightGray); + } catch (IllegalArgumentException iae) { + fail("Decode of \"lightGray\" should succeed!"); + } + + assertEquals((Color) null, GraphicsUtilities.decodeColor("null")); + + int transparency = -1; + for (CSSColor color : CSSColor.values()) { + transparency = (transparency + 1) % 256; + Color originalColor = color.getColor(); + Color translucentColor = ColorUtilities.toTransparentColor(color, transparency); + String value = (transparency == 255) + ? String.format("#%02X%02X%02X", + originalColor.getRed(), originalColor.getGreen(), originalColor.getBlue()) + : String.format("0x%02X%02X%02X%02X", + originalColor.getRed(), originalColor.getGreen(), originalColor.getBlue(), transparency); + String testValue = ColorUtilities.toStringValue(translucentColor); + assertEquals(value, testValue); + } + + } +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/ColorUtilitiesTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CornerRadiiTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/DimensionsTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/DimensionsTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/DimensionsTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/DimensionsTest.java Tue Oct 31 19:15:47 2023 @@ -1,90 +1,90 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import org.apache.pivot.wtk.Dimensions; -import org.apache.pivot.wtk.Insets; - - -/** - * Tests the {@link Dimensions} class which is used extensively - * in the "wtk" source, and deserves good tests. - */ -public class DimensionsTest { - - @Test - public void test() { - Dimensions zero = Dimensions.ZERO; - Dimensions zeroA = new Dimensions(0, 0); - Dimensions zeroB = new Dimensions(0); - Dimensions one = new Dimensions(1, 1); - Dimensions oneA = zero.expand(1); - Dimensions zeroC = oneA.expand(-1, -1); - - Dimensions seven = new Dimensions(7); - Dimensions sevenA = new Dimensions(7, 7); - Dimensions sevenB = zero.expand(7); - Dimensions sevenC = zeroA.expand(7, 7); - - Dimensions a = Dimensions.decode("2 x 3"); - Dimensions a1 = new Dimensions(2, 3); - Dimensions b = Dimensions.decode("{width:4, height:5}"); - Dimensions b1 = new Dimensions(4, 5); - Dimensions c = Dimensions.decode("1 , 2"); - Dimensions c1 = new Dimensions(1, 2); - Dimensions d = Dimensions.decode("[ 17, 23]"); - Dimensions d1 = new Dimensions(17, 23); - Dimensions e = Dimensions.decode("23 ; 45"); - Dimensions e1 = new Dimensions(23, 45); - - Insets i1 = new Insets(1, 2, 1, 2); - Dimensions f = e1.expand(i1); - Dimensions f1 = new Dimensions(27, 47); - - assertEquals(zero, zeroA); - assertEquals(one, oneA); - assertEquals(zeroA, zeroB); - assertEquals(zero, zeroC); - - assertEquals(seven, sevenA); - assertEquals(seven, sevenB); - assertEquals(sevenB, sevenC); - - assertEquals(a, a1); - assertEquals(b, b1); - assertEquals(c, c1); - assertEquals(d, d1); - assertEquals(e, e1); - assertEquals(f, f1); - } - - @Test(expected = IllegalArgumentException.class) - public void test1() { - Dimensions ugly = Dimensions.decode("a x 3"); - } - - @Test(expected = IllegalArgumentException.class) - public void test2() { - Dimensions ugly = Dimensions.decode("1 : 3"); - } - -} - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.apache.pivot.wtk.Dimensions; +import org.apache.pivot.wtk.Insets; + + +/** + * Tests the {@link Dimensions} class which is used extensively + * in the "wtk" source, and deserves good tests. + */ +public class DimensionsTest { + + @Test + public void test() { + Dimensions zero = Dimensions.ZERO; + Dimensions zeroA = new Dimensions(0, 0); + Dimensions zeroB = new Dimensions(0); + Dimensions one = new Dimensions(1, 1); + Dimensions oneA = zero.expand(1); + Dimensions zeroC = oneA.expand(-1, -1); + + Dimensions seven = new Dimensions(7); + Dimensions sevenA = new Dimensions(7, 7); + Dimensions sevenB = zero.expand(7); + Dimensions sevenC = zeroA.expand(7, 7); + + Dimensions a = Dimensions.decode("2 x 3"); + Dimensions a1 = new Dimensions(2, 3); + Dimensions b = Dimensions.decode("{width:4, height:5}"); + Dimensions b1 = new Dimensions(4, 5); + Dimensions c = Dimensions.decode("1 , 2"); + Dimensions c1 = new Dimensions(1, 2); + Dimensions d = Dimensions.decode("[ 17, 23]"); + Dimensions d1 = new Dimensions(17, 23); + Dimensions e = Dimensions.decode("23 ; 45"); + Dimensions e1 = new Dimensions(23, 45); + + Insets i1 = new Insets(1, 2, 1, 2); + Dimensions f = e1.expand(i1); + Dimensions f1 = new Dimensions(27, 47); + + assertEquals(zero, zeroA); + assertEquals(one, oneA); + assertEquals(zeroA, zeroB); + assertEquals(zero, zeroC); + + assertEquals(seven, sevenA); + assertEquals(seven, sevenB); + assertEquals(sevenB, sevenC); + + assertEquals(a, a1); + assertEquals(b, b1); + assertEquals(c, c1); + assertEquals(d, d1); + assertEquals(e, e1); + assertEquals(f, f1); + } + + @Test(expected = IllegalArgumentException.class) + public void test1() { + Dimensions ugly = Dimensions.decode("a x 3"); + } + + @Test(expected = IllegalArgumentException.class) + public void test2() { + Dimensions ugly = Dimensions.decode("1 : 3"); + } + +} + Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/DimensionsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/GaugeTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/GaugeTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/GaugeTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/GaugeTest.java Tue Oct 31 19:15:47 2023 @@ -1,123 +1,123 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import org.apache.pivot.wtk.Gauge; -import org.apache.pivot.wtk.GaugeListener; -import org.apache.pivot.wtk.Origin; - - -public final class GaugeTest implements GaugeListener<Integer> { - private int originChangeCount = 0; - private int valueChangeCount = 0; - private int textChangeCount = 0; - private int minMaxChangeCount = 0; - private int warningCriticalChangeCount = 0; - - @Override - public void originChanged(final Gauge<Integer> gauge, final Origin previousOrigin) { - System.out.println("Origin changed to " + gauge.getOrigin()); - originChangeCount++; - } - - @Override - public void valueChanged(final Gauge<Integer> gauge, final Integer previousValue) { - System.out.println("Value changed to " + gauge.getValue()); - valueChangeCount++; - } - - @Override - public void textChanged(final Gauge<Integer> gauge, final String previousText) { - System.out.println("Text changed to " + gauge.getText()); - textChangeCount++; - } - - @Override - public void minValueChanged(final Gauge<Integer> gauge, final Integer previousMinValue) { - System.out.println("Min changed: min=" + gauge.getMinValue()); - minMaxChangeCount++; - } - - @Override - public void maxValueChanged(final Gauge<Integer> gauge, final Integer previousMaxValue) { - System.out.println("Max changed: max=" + gauge.getMaxValue()); - minMaxChangeCount++; - } - - @Override - public void warningLevelChanged(final Gauge<Integer> gauge, final Integer previousWarningLevel) { - System.out.println("Warning level changed: warning=" + gauge.getWarningLevel()); - warningCriticalChangeCount++; - } - - @Override - public void criticalLevelChanged(final Gauge<Integer> gauge, final Integer previousCriticalLevel) { - System.out.println("Critical level changed: critical=" + gauge.getCriticalLevel()); - warningCriticalChangeCount++; - } - - @Test - public void testListeners() { - Gauge<Integer> gauge = new Gauge<>(); - gauge.getGaugeListeners().add(this); - - // Test all the listeners getting fired as they should - gauge.setOrigin(Origin.NORTH); // no change here - gauge.setOrigin(Origin.SOUTH); - gauge.setOrigin(Origin.SOUTH); // again, no change - gauge.setOrigin(Origin.EAST); - gauge.setOrigin(Origin.WEST); - gauge.setOrigin(Origin.NORTH); - - gauge.setMinValue(0); - gauge.setMaxValue(100); - gauge.setMinValue(0); - gauge.setMaxValue(100); - - gauge.setWarningLevel(10); - gauge.setWarningLevel(80); - gauge.setWarningLevel(80); - gauge.setCriticalLevel(10); - gauge.setCriticalLevel(10); - gauge.setCriticalLevel(90); - - gauge.setText(null); - gauge.setText(""); - gauge.setText(""); - gauge.setText("20%"); - gauge.setText("20%"); - gauge.setText("100%"); - gauge.setText(null); - gauge.setText("100%"); - - gauge.setValue(0); - gauge.setValue(2); - gauge.setValue(10); - gauge.setValue(0); - - // Now check for proper listener event counts - assertEquals(originChangeCount, 4); - assertEquals(minMaxChangeCount, 2); - assertEquals(warningCriticalChangeCount, 4); - assertEquals(textChangeCount, 5); - assertEquals(valueChangeCount, 4); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.apache.pivot.wtk.Gauge; +import org.apache.pivot.wtk.GaugeListener; +import org.apache.pivot.wtk.Origin; + + +public final class GaugeTest implements GaugeListener<Integer> { + private int originChangeCount = 0; + private int valueChangeCount = 0; + private int textChangeCount = 0; + private int minMaxChangeCount = 0; + private int warningCriticalChangeCount = 0; + + @Override + public void originChanged(final Gauge<Integer> gauge, final Origin previousOrigin) { + System.out.println("Origin changed to " + gauge.getOrigin()); + originChangeCount++; + } + + @Override + public void valueChanged(final Gauge<Integer> gauge, final Integer previousValue) { + System.out.println("Value changed to " + gauge.getValue()); + valueChangeCount++; + } + + @Override + public void textChanged(final Gauge<Integer> gauge, final String previousText) { + System.out.println("Text changed to " + gauge.getText()); + textChangeCount++; + } + + @Override + public void minValueChanged(final Gauge<Integer> gauge, final Integer previousMinValue) { + System.out.println("Min changed: min=" + gauge.getMinValue()); + minMaxChangeCount++; + } + + @Override + public void maxValueChanged(final Gauge<Integer> gauge, final Integer previousMaxValue) { + System.out.println("Max changed: max=" + gauge.getMaxValue()); + minMaxChangeCount++; + } + + @Override + public void warningLevelChanged(final Gauge<Integer> gauge, final Integer previousWarningLevel) { + System.out.println("Warning level changed: warning=" + gauge.getWarningLevel()); + warningCriticalChangeCount++; + } + + @Override + public void criticalLevelChanged(final Gauge<Integer> gauge, final Integer previousCriticalLevel) { + System.out.println("Critical level changed: critical=" + gauge.getCriticalLevel()); + warningCriticalChangeCount++; + } + + @Test + public void testListeners() { + Gauge<Integer> gauge = new Gauge<>(); + gauge.getGaugeListeners().add(this); + + // Test all the listeners getting fired as they should + gauge.setOrigin(Origin.NORTH); // no change here + gauge.setOrigin(Origin.SOUTH); + gauge.setOrigin(Origin.SOUTH); // again, no change + gauge.setOrigin(Origin.EAST); + gauge.setOrigin(Origin.WEST); + gauge.setOrigin(Origin.NORTH); + + gauge.setMinValue(0); + gauge.setMaxValue(100); + gauge.setMinValue(0); + gauge.setMaxValue(100); + + gauge.setWarningLevel(10); + gauge.setWarningLevel(80); + gauge.setWarningLevel(80); + gauge.setCriticalLevel(10); + gauge.setCriticalLevel(10); + gauge.setCriticalLevel(90); + + gauge.setText(null); + gauge.setText(""); + gauge.setText(""); + gauge.setText("20%"); + gauge.setText("20%"); + gauge.setText("100%"); + gauge.setText(null); + gauge.setText("100%"); + + gauge.setValue(0); + gauge.setValue(2); + gauge.setValue(10); + gauge.setValue(0); + + // Now check for proper listener event counts + assertEquals(originChangeCount, 4); + assertEquals(minMaxChangeCount, 2); + assertEquals(warningCriticalChangeCount, 4); + assertEquals(textChangeCount, 5); + assertEquals(valueChangeCount, 4); + } +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/GaugeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/InsetsTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/InsetsTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/InsetsTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/InsetsTest.java Tue Oct 31 19:15:47 2023 @@ -1,98 +1,98 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import org.apache.pivot.wtk.Dimensions; -import org.apache.pivot.wtk.Insets; - - -/** - * Tests the {@link Insets} class which is used extensively - * in the "wtk" source, and deserves good tests. - */ -public class InsetsTest { - - @Test - public void test() { - Insets i0 = Insets.NONE; - Insets i0a = new Insets(0); - Insets i1 = new Insets(1); - Insets i1a = new Insets(1, 1, 1, 1); - Insets i2 = new Insets(2); - Insets i2a = new Insets(2.0f); - Insets i2b = Insets.decode("[ 2, 2, 2, 2 ]"); - - Insets i3 = new Insets(1, 2, 3, 4); - Insets i3a = Insets.decode("{top:1, left:2, bottom:3, right:4}"); - - Insets i4 = new Insets(5, 6, 7, 8); - Insets i4a = Insets.decode("5, 6; 7, 8"); - - Dimensions dim5 = new Dimensions(5); - Insets i5 = new Insets(dim5); - Insets i5a = new Insets(2, 2, 3, 3); - Dimensions dim5a = i5.getSize(); - Dimensions dim5b = i5a.getSize(); - - assertEquals(i0, i0a); - assertEquals(i1, i1a); - assertEquals(i2, i2a); - assertEquals(i2, i2b); - - assertEquals(i3, i3a); - assertEquals(i3.toString(), "Insets [1, 2, 3, 4]"); - - assertEquals(i0.getWidth(), 0); - assertEquals(i0.getHeight(), 0); - assertEquals(i3.getWidth(), 6); - assertEquals(i3.getHeight(), 4); - - assertEquals(i4, i4a); - assertEquals(i4a.getWidth(), 14); - assertEquals(i4a.getHeight(), 12); - assertEquals(i4a.toString(), "Insets [5, 6, 7, 8]"); - - assertEquals(i5, i5a); - assertEquals(dim5, dim5a); - assertEquals(dim5a, dim5b); - assertEquals(i5.toString(), "Insets [2, 2, 3, 3]"); - } - - @Test - public void testNullEmpty() { - try { - Insets.decode(null); - fail("Insets.decode of null string should fail!"); - } catch (IllegalArgumentException iae) { - System.out.println("Valid exception: " + iae.getMessage()); - assertEquals(iae.getMessage(), "padding/margin must not be null or empty."); - } - - try { - Insets.decode(""); - fail("Insets.decode of empty string should fail!"); - } catch (IllegalArgumentException iae) { - System.out.println("Valid exception: " + iae.getMessage()); - assertEquals(iae.getMessage(), "padding/margin must not be null or empty."); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import org.apache.pivot.wtk.Dimensions; +import org.apache.pivot.wtk.Insets; + + +/** + * Tests the {@link Insets} class which is used extensively + * in the "wtk" source, and deserves good tests. + */ +public class InsetsTest { + + @Test + public void test() { + Insets i0 = Insets.NONE; + Insets i0a = new Insets(0); + Insets i1 = new Insets(1); + Insets i1a = new Insets(1, 1, 1, 1); + Insets i2 = new Insets(2); + Insets i2a = new Insets(2.0f); + Insets i2b = Insets.decode("[ 2, 2, 2, 2 ]"); + + Insets i3 = new Insets(1, 2, 3, 4); + Insets i3a = Insets.decode("{top:1, left:2, bottom:3, right:4}"); + + Insets i4 = new Insets(5, 6, 7, 8); + Insets i4a = Insets.decode("5, 6; 7, 8"); + + Dimensions dim5 = new Dimensions(5); + Insets i5 = new Insets(dim5); + Insets i5a = new Insets(2, 2, 3, 3); + Dimensions dim5a = i5.getSize(); + Dimensions dim5b = i5a.getSize(); + + assertEquals(i0, i0a); + assertEquals(i1, i1a); + assertEquals(i2, i2a); + assertEquals(i2, i2b); + + assertEquals(i3, i3a); + assertEquals(i3.toString(), "Insets [1, 2, 3, 4]"); + + assertEquals(i0.getWidth(), 0); + assertEquals(i0.getHeight(), 0); + assertEquals(i3.getWidth(), 6); + assertEquals(i3.getHeight(), 4); + + assertEquals(i4, i4a); + assertEquals(i4a.getWidth(), 14); + assertEquals(i4a.getHeight(), 12); + assertEquals(i4a.toString(), "Insets [5, 6, 7, 8]"); + + assertEquals(i5, i5a); + assertEquals(dim5, dim5a); + assertEquals(dim5a, dim5b); + assertEquals(i5.toString(), "Insets [2, 2, 3, 3]"); + } + + @Test + public void testNullEmpty() { + try { + Insets.decode(null); + fail("Insets.decode of null string should fail!"); + } catch (IllegalArgumentException iae) { + System.out.println("Valid exception: " + iae.getMessage()); + assertEquals(iae.getMessage(), "padding/margin must not be null or empty."); + } + + try { + Insets.decode(""); + fail("Insets.decode of empty string should fail!"); + } catch (IllegalArgumentException iae) { + System.out.println("Valid exception: " + iae.getMessage()); + assertEquals(iae.getMessage(), "padding/margin must not be null or empty."); + } + } +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/InsetsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/LimitsTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/LimitsTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/LimitsTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/LimitsTest.java Tue Oct 31 19:15:47 2023 @@ -1,78 +1,78 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the lmecific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import org.apache.pivot.wtk.Limits; - - -/** - * Tests the {@link Limits} class which is used extensively - * in the "wtk" source, and deserves good tests. - */ -public class LimitsTest { - - @Test - public void test() { - Limits lmMinus1 = new Limits(-1, 0); - Limits lm0 = new Limits(0); - Limits lm1 = new Limits(0, 1); - Limits lm2 = Limits.decode("[0, 1]"); - Limits lm3 = Limits.decode("{minimum:2, maximum:3}"); - Limits lm3a = new Limits(2, 3); - Limits lm4 = new Limits(4); - Limits lm5 = new Limits(3, 4); - Limits lm5a = new Limits(3, 4); - Limits lm5b = Limits.decode("[3, 4]"); - Limits lmN = new Limits(0, 4); - Limits lm6 = Limits.decode("5; 6"); - Limits lm6a = new Limits(5, 6); - Limits lm7 = Limits.decode("9 - 10"); - Limits lm7a = new Limits(9, 10); - - assertEquals(lmMinus1.range(), 2); - assertEquals(lm0.range(), 1); - - assertTrue(lm1.contains(0)); - assertTrue(lm1.contains(1)); - assertFalse(lm1.contains(2)); - - assertFalse(lm0.equals(lm1)); - assertTrue(lm1.equals(lm2)); - assertEquals(lm3, lm3a); - - assertTrue(lm5.equals(lm5a)); - - assertEquals(lm2.minimum, 0); - assertEquals(lm2.maximum, 1); - assertTrue(lm5a.equals(lm5b)); - - assertEquals(lmN.constrain(5), 4); - assertEquals(lmN.constrain(-2), 0); - - assertEquals(lm6, lm6a); - assertEquals(lm6.toString(), "Limits [5-6]"); - assertEquals(lm7, lm7a); - assertEquals(lm7.toString(), "Limits [9-10]"); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the lmecific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.apache.pivot.wtk.Limits; + + +/** + * Tests the {@link Limits} class which is used extensively + * in the "wtk" source, and deserves good tests. + */ +public class LimitsTest { + + @Test + public void test() { + Limits lmMinus1 = new Limits(-1, 0); + Limits lm0 = new Limits(0); + Limits lm1 = new Limits(0, 1); + Limits lm2 = Limits.decode("[0, 1]"); + Limits lm3 = Limits.decode("{minimum:2, maximum:3}"); + Limits lm3a = new Limits(2, 3); + Limits lm4 = new Limits(4); + Limits lm5 = new Limits(3, 4); + Limits lm5a = new Limits(3, 4); + Limits lm5b = Limits.decode("[3, 4]"); + Limits lmN = new Limits(0, 4); + Limits lm6 = Limits.decode("5; 6"); + Limits lm6a = new Limits(5, 6); + Limits lm7 = Limits.decode("9 - 10"); + Limits lm7a = new Limits(9, 10); + + assertEquals(lmMinus1.range(), 2); + assertEquals(lm0.range(), 1); + + assertTrue(lm1.contains(0)); + assertTrue(lm1.contains(1)); + assertFalse(lm1.contains(2)); + + assertFalse(lm0.equals(lm1)); + assertTrue(lm1.equals(lm2)); + assertEquals(lm3, lm3a); + + assertTrue(lm5.equals(lm5a)); + + assertEquals(lm2.minimum, 0); + assertEquals(lm2.maximum, 1); + assertTrue(lm5a.equals(lm5b)); + + assertEquals(lmN.constrain(5), 4); + assertEquals(lmN.constrain(-2), 0); + + assertEquals(lm6, lm6a); + assertEquals(lm6.toString(), "Limits [5-6]"); + assertEquals(lm7, lm7a); + assertEquals(lm7.toString(), "Limits [9-10]"); + } + +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/LimitsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java?rev=1913470&r1=1913469&r2=1913470&view=diff ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java (original) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java Tue Oct 31 19:15:47 2023 @@ -1,73 +1,73 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pivot.wtk.test; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import org.apache.pivot.wtk.Meter; -import org.apache.pivot.wtk.MeterListener; -import org.apache.pivot.wtk.Orientation; - - -public final class MeterTest implements MeterListener { - private int percentChangeCount = 0; - private int textChangeCount = 0; - private int orientationChangeCount = 0; - - @Override - public void percentageChanged(final Meter meter, final double previousPercentage) { - percentChangeCount++; - } - - @Override - public void textChanged(final Meter meter, final String previousText) { - textChangeCount++; - } - - @Override - public void orientationChanged(final Meter meter) { - orientationChangeCount++; - } - - @Test - public void testListeners() { - Meter meter = new Meter(); - meter.getMeterListeners().add(this); - - // Test all the listeners getting fired as they should - meter.setText("abc"); - meter.setText(null); - meter.setText(null); - meter.setText("123"); - meter.setText("123"); - meter.setOrientation(Orientation.HORIZONTAL); - meter.setOrientation(Orientation.VERTICAL); - meter.setOrientation(Orientation.HORIZONTAL); - meter.setPercentage(0.25); - meter.setPercentage(0.25); - meter.setPercentage(0.5); - meter.setPercentage(0.75); - meter.setPercentage(1.0); - - // Now check for proper listener event counts - assertEquals(percentChangeCount, 4); - assertEquals(textChangeCount, 3); - assertEquals(orientationChangeCount, 2); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.apache.pivot.wtk.Meter; +import org.apache.pivot.wtk.MeterListener; +import org.apache.pivot.wtk.Orientation; + + +public final class MeterTest implements MeterListener { + private int percentChangeCount = 0; + private int textChangeCount = 0; + private int orientationChangeCount = 0; + + @Override + public void percentageChanged(final Meter meter, final double previousPercentage) { + percentChangeCount++; + } + + @Override + public void textChanged(final Meter meter, final String previousText) { + textChangeCount++; + } + + @Override + public void orientationChanged(final Meter meter) { + orientationChangeCount++; + } + + @Test + public void testListeners() { + Meter meter = new Meter(); + meter.getMeterListeners().add(this); + + // Test all the listeners getting fired as they should + meter.setText("abc"); + meter.setText(null); + meter.setText(null); + meter.setText("123"); + meter.setText("123"); + meter.setOrientation(Orientation.HORIZONTAL); + meter.setOrientation(Orientation.VERTICAL); + meter.setOrientation(Orientation.HORIZONTAL); + meter.setPercentage(0.25); + meter.setPercentage(0.25); + meter.setPercentage(0.5); + meter.setPercentage(0.75); + meter.setPercentage(1.0); + + // Now check for proper listener event counts + assertEquals(percentChangeCount, 4); + assertEquals(textChangeCount, 3); + assertEquals(orientationChangeCount, 2); + } +} Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/RangeSelectionTest.java ------------------------------------------------------------------------------ svn:eol-style = native