diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2009-12-22 17:20:51 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2009-12-22 17:20:51 +0000 |
commit | 37b744039a701d5aafd44997a195c696261d3fea (patch) | |
tree | 504f0326b76734cf106ece1b67cf2fca8fd48ac3 /test/java/org/apache/fop | |
parent | a0f281543e947da203e9cfd5cb3559e32912beb4 (diff) | |
download | xmlgraphics-fop-37b744039a701d5aafd44997a195c696261d3fea.tar.gz xmlgraphics-fop-37b744039a701d5aafd44997a195c696261d3fea.zip |
Bugzilla #48071: made the MinOptMax class immutable. Also, lots of clean ups and minor refactorings.
Patch submitted by Alexander Kiel.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@893238 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop')
-rw-r--r-- | test/java/org/apache/fop/StandardTestSuite.java | 5 | ||||
-rw-r--r-- | test/java/org/apache/fop/traits/MinOptMaxTest.java | 199 |
2 files changed, 202 insertions, 2 deletions
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index 250ddaad6..281301789 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -34,6 +34,7 @@ import org.apache.fop.render.pdf.PDFCMapTestCase; import org.apache.fop.render.pdf.PDFEncodingTestCase; import org.apache.fop.render.pdf.PDFsRGBSettingsTestCase; import org.apache.fop.render.rtf.RichTextFormatTestSuite; +import org.apache.fop.traits.MinOptMaxTest; /** * Test suite for basic functionality of FOP. @@ -45,8 +46,7 @@ public class StandardTestSuite { * @return the test suite */ public static Test suite() { - TestSuite suite = new TestSuite( - "Basic functionality test suite for FOP"); + TestSuite suite = new TestSuite("Basic functionality test suite for FOP"); //$JUnit-BEGIN$ suite.addTest(BasicDriverTestSuite.suite()); suite.addTest(UtilityCodeTestSuite.suite()); @@ -62,6 +62,7 @@ public class StandardTestSuite { suite.addTest(new TestSuite(IFMimickingTestCase.class)); suite.addTest(new TestSuite(PageBoundariesTest.class)); suite.addTest(new TestSuite(PageScaleTest.class)); + suite.addTest(new TestSuite(MinOptMaxTest.class)); //$JUnit-END$ return suite; } diff --git a/test/java/org/apache/fop/traits/MinOptMaxTest.java b/test/java/org/apache/fop/traits/MinOptMaxTest.java new file mode 100644 index 000000000..17f46b7b0 --- /dev/null +++ b/test/java/org/apache/fop/traits/MinOptMaxTest.java @@ -0,0 +1,199 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.traits; + +import junit.framework.TestCase; + +/** + * Tests the {@link MinOptMaxTest} class. + */ +public class MinOptMaxTest extends TestCase { + + /** + * Tests that the constant <code>MinOptMax.ZERO</code> is really zero. + */ + public void testZero() { + assertEquals(MinOptMax.getInstance(0), MinOptMax.ZERO); + } + + public void testNewStiffMinOptMax() { + MinOptMax value = MinOptMax.getInstance(1); + assertTrue(value.isStiff()); + assertEquals(1, value.getMin()); + assertEquals(1, value.getOpt()); + assertEquals(1, value.getMax()); + } + + public void testNewMinOptMax() { + MinOptMax value = MinOptMax.getInstance(1, 2, 3); + assertTrue(value.isElastic()); + assertEquals(1, value.getMin()); + assertEquals(2, value.getOpt()); + assertEquals(3, value.getMax()); + } + + /** + * Test that it is possible to create stiff instances with the normal factory method. + */ + public void testNewMinOptMaxStiff() { + MinOptMax value = MinOptMax.getInstance(1, 1, 1); + assertTrue(value.isStiff()); + assertEquals(1, value.getMin()); + assertEquals(1, value.getOpt()); + assertEquals(1, value.getMax()); + } + + public void testNewMinOptMaxMinGreaterOpt() { + try { + MinOptMax.getInstance(1, 0, 2); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("min (1) > opt (0)", e.getMessage()); + } + } + + public void testNewMinOptMaxMaxSmallerOpt() { + try { + MinOptMax.getInstance(0, 1, 0); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("max (0) < opt (1)", e.getMessage()); + } + } + + public void testShrinkablility() { + assertEquals(0, MinOptMax.getInstance(1).getShrink()); + assertEquals(1, MinOptMax.getInstance(1, 2, 2).getShrink()); + assertEquals(2, MinOptMax.getInstance(1, 3, 3).getShrink()); + } + + public void testStrechablilty() { + assertEquals(0, MinOptMax.getInstance(1).getStretch()); + assertEquals(1, MinOptMax.getInstance(1, 1, 2).getStretch()); + assertEquals(2, MinOptMax.getInstance(1, 1, 3).getStretch()); + } + + public void testPlus() { + assertEquals(MinOptMax.ZERO, + MinOptMax.ZERO.plus(MinOptMax.ZERO)); + assertEquals(MinOptMax.getInstance(1, 2, 3), + MinOptMax.ZERO.plus(MinOptMax.getInstance(1, 2, 3))); + assertEquals(MinOptMax.getInstance(2, 4, 6), + MinOptMax.getInstance(1, 2, 3).plus(MinOptMax.getInstance(1, 2, 3))); + assertEquals(MinOptMax.getInstance(4, 5, 6), MinOptMax.getInstance(1, 2, 3).plus(3)); + } + + public void testMinus() { + assertEquals(MinOptMax.ZERO, + MinOptMax.ZERO.minus(MinOptMax.ZERO)); + assertEquals(MinOptMax.getInstance(1, 2, 3), + MinOptMax.getInstance(1, 2, 3).plus(MinOptMax.ZERO)); + assertEquals(MinOptMax.getInstance(1, 2, 3), + MinOptMax.getInstance(2, 4, 6).minus(MinOptMax.getInstance(1, 2, 3))); + assertEquals(MinOptMax.getInstance(1, 2, 3), MinOptMax.getInstance(5, 6, 7).minus(4)); + } + + public void testMinusFail1() { + try { + MinOptMax.ZERO.minus(MinOptMax.getInstance(1, 2, 3)); + fail(); + } catch (ArithmeticException e) { + // Ok + } + } + + public void testMinusFail2() { + try { + MinOptMax.getInstance(1, 2, 3).minus(MinOptMax.getInstance(1, 3, 3)); + fail(); + } catch (ArithmeticException e) { + // Ok + } + } + + public void testMinusFail3() { + try { + MinOptMax.ZERO.minus(MinOptMax.getInstance(1, 1, 2)); + fail(); + } catch (ArithmeticException e) { + // Ok + } + } + + public void testMinusFail4() { + try { + MinOptMax.getInstance(1, 2, 3).minus(MinOptMax.getInstance(1, 1, 3)); + fail(); + } catch (ArithmeticException e) { + // Ok + } + } + + public void testMult() { + assertEquals(MinOptMax.ZERO, MinOptMax.ZERO.mult(0)); + assertEquals(MinOptMax.getInstance(1, 2, 3), MinOptMax.getInstance(1, 2, 3).mult(1)); + assertEquals(MinOptMax.getInstance(2, 4, 6), MinOptMax.getInstance(1, 2, 3).mult(2)); + } + + public void testMultFail() { + try { + MinOptMax.getInstance(1, 2, 3).mult(-1); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("factor < 0; was: -1", e.getMessage()); + } + } + + public void testNonZero() { + assertFalse(MinOptMax.ZERO.isNonZero()); + assertTrue(MinOptMax.getInstance(1).isNonZero()); + assertTrue(MinOptMax.getInstance(1, 2, 3).isNonZero()); + } + + public void testExtendMinimum() { + assertEquals(MinOptMax.getInstance(1, 1, 1), + MinOptMax.ZERO.extendMinimum(1)); + assertEquals(MinOptMax.getInstance(1, 2, 3), + MinOptMax.getInstance(1, 2, 3).extendMinimum(1)); + assertEquals(MinOptMax.getInstance(2, 2, 3), + MinOptMax.getInstance(1, 2, 3).extendMinimum(2)); + assertEquals(MinOptMax.getInstance(3, 3, 3), + MinOptMax.getInstance(1, 2, 3).extendMinimum(3)); + assertEquals(MinOptMax.getInstance(4, 4, 4), + MinOptMax.getInstance(1, 2, 3).extendMinimum(4)); + } + + public void testEquals() { + MinOptMax number = MinOptMax.getInstance(1, 3, 5); + assertEquals(number, number); + assertEquals(number, MinOptMax.getInstance(1, 3, 5)); + assertFalse(number.equals(MinOptMax.getInstance(2, 3, 5))); + assertFalse(number.equals(MinOptMax.getInstance(1, 4, 5))); + assertFalse(number.equals(MinOptMax.getInstance(1, 3, 4))); + assertFalse(number.equals(null)); + assertFalse(number.equals(new Integer(1))); + } + + public void testHashCode() { + MinOptMax number = MinOptMax.getInstance(1, 2, 3); + assertEquals(number.hashCode(), number.hashCode()); + assertEquals(number.hashCode(), MinOptMax.getInstance(1, 2, 3).hashCode()); + } +} |