Clover icon

Magnolia Imaging Module 3.2.3

  1. Project Clover database Fri Nov 6 2015 14:54:03 CET
  2. Package info.magnolia.imaging.operations.cropresize

File BoundedResizeTest.java

 

Code metrics

0
24
11
1
124
66
11
0.46
2.18
11
1

Classes

Class Line # Actions
BoundedResizeTest 48 24 0% 11 0
1.0100%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2015 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging.operations.cropresize;
35   
36    import static org.junit.Assert.assertEquals;
37   
38    import info.magnolia.imaging.AbstractImagingTest;
39   
40    import java.awt.image.BufferedImage;
41   
42    import org.junit.Before;
43    import org.junit.Test;
44   
45    /**
46    * @version $Id$
47    */
 
48    public class BoundedResizeTest extends AbstractImagingTest {
49   
50    BoundedResize op;
51   
 
52  9 toggle @Override
53    @Before
54    public void setUp() throws Exception {
55  9 super.setUp();
56  9 op = new BoundedResize();
57    }
58   
 
59  1 toggle @Test
60    public void testJustResizeIfTargetRatioIsEquivalentToSourceRatio() throws Exception {
61  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 400, 300, 400, 300);
62    }
63   
 
64  1 toggle @Test
65    public void testKeepsOriginalRatioAndCompliesToSmallestMaximumDimension() throws Exception {
66    // source is w:1600*h:1200
67  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 2500, 300, 400, 300);
68  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 200, 3000, 200, 150);
69    }
70   
 
71  1 toggle @Test
72    public void testKeepsOriginalRatioAndCompliesToSmallestMaximumDimensionForVerticalSourceToo() throws Exception {
73    // source is w:1200*h:1600
74  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getVerticalTestImage(), 2500, 400, 300, 400);
75  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getVerticalTestImage(), 300, 4000, 300, 400);
76    }
77   
 
78  1 toggle @Test
79    public void testKeepsOriginalRatioAndCompliesToSmallestMaximumDimensionForSquareSourceToo() throws Exception {
80    // source is w:500*h:500
81  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSquareTestImage(), 2500, 400, 400, 400);
82  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSquareTestImage(), 300, 4000, 300, 300);
83    }
84   
 
85  1 toggle @Test
86    public void testAlsoWorksWithOblongImages() throws Exception {
87  1 final BufferedImage img = generateArbitraryTestImage(228, 700);
88  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(img, 160, 260, 84, 260);
89    }
90   
 
91  1 toggle @Test
92    public void testAnotherOblongCase() throws Exception {
93  1 final BufferedImage img = generateArbitraryTestImage(800, 200);
94  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(img, 160, 160, 160, 40);
95    }
96   
 
97  1 toggle @Test(expected = IllegalArgumentException.class)
98    public void testWhatHappensIfWeOnlySpecifyMaxWidth() throws Exception {
99  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 400, 0, 400, 300);
100    }
101   
 
102  1 toggle @Test
103    public void testSmallImageNotEnlargedWhileExpandFalse() throws Exception {
104  1 op.setExpand(false);
105  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSmallTestImage(), 400, 400, 202, 51);
106    }
107   
 
108  1 toggle @Test
109    public void testSmallImageIsEnlargedWhileExpandTrue() throws Exception {
110  1 op.setExpand(true);
111  1 doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSmallTestImage(), 400, 400, 400, 100);
112    }
113   
 
114  12 toggle private void doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(final BufferedImage src, final int maxWidth, final int maxHeight, final int expectedWidth, final int expectedHeight) throws Exception {
115  12 op.setMaxWidth(maxWidth);
116  12 op.setMaxHeight(maxHeight);
117   
118  12 final BufferedImage res = op.apply(src, null);
119  11 write(String.format("%dx%x-to-%dx%d", maxWidth, maxHeight, expectedWidth, expectedHeight), res, BASIC_JPEG);
120   
121  11 assertEquals(expectedWidth, res.getWidth());
122  11 assertEquals(expectedHeight, res.getHeight());
123    }
124    }