1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 11 |
Complexity Density: 0.46 |
|
45 |
|
public class BoundedResizeTest extends AbstractImagingTest { |
46 |
|
|
47 |
|
BoundedResize op; |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
49 |
9 |
@Override... |
50 |
|
@Before |
51 |
|
public void setUp() throws Exception { |
52 |
9 |
super.setUp(); |
53 |
9 |
op = new BoundedResize(); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
56 |
1 |
@Test... |
57 |
|
public void justResizeIfTargetRatioIsEquivalentToSourceRatio() throws Exception { |
58 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 400, 300, 400, 300); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void keepsOriginalRatioAndCompliesToSmallestMaximumDimension() throws Exception { |
63 |
|
|
64 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 2500, 300, 400, 300); |
65 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 200, 3000, 200, 150); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
68 |
1 |
@Test... |
69 |
|
public void keepsOriginalRatioAndCompliesToSmallestMaximumDimensionForVerticalSourceToo() throws Exception { |
70 |
|
|
71 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getVerticalTestImage(), 2500, 400, 300, 400); |
72 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getVerticalTestImage(), 300, 4000, 300, 400); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
75 |
1 |
@Test... |
76 |
|
public void keepsOriginalRatioAndCompliesToSmallestMaximumDimensionForSquareSourceToo() throws Exception { |
77 |
|
|
78 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSquareTestImage(), 2500, 400, 400, 400); |
79 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSquareTestImage(), 300, 4000, 300, 300); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void alsoWorksWithOblongImages() throws Exception { |
84 |
1 |
final BufferedImage img = generateArbitraryTestImage(228, 700); |
85 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(img, 160, 260, 84, 260); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void anotherOblongCase() throws Exception { |
90 |
1 |
final BufferedImage img = generateArbitraryTestImage(800, 200); |
91 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(img, 160, 160, 160, 40); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
94 |
1 |
@Test(expected = IllegalArgumentException.class)... |
95 |
|
public void whatHappensIfWeOnlySpecifyMaxWidth() throws Exception { |
96 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getHorizontalTestImage(), 400, 0, 400, 300); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void smallImageNotEnlargedWhileExpandFalse() throws Exception { |
101 |
1 |
op.setExpand(false); |
102 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSmallTestImage(), 400, 400, 202, 51); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
105 |
1 |
@Test... |
106 |
|
public void smallImageIsEnlargedWhileExpandTrue() throws Exception { |
107 |
1 |
op.setExpand(true); |
108 |
1 |
doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(getSmallTestImage(), 400, 400, 400, 100); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
111 |
12 |
private void doTestKeepsOriginalRatioAndCompliesToSmallestMaximumDimension(final BufferedImage src, final int maxWidth, final int maxHeight, final int expectedWidth, final int expectedHeight) throws Exception {... |
112 |
12 |
op.setMaxWidth(maxWidth); |
113 |
12 |
op.setMaxHeight(maxHeight); |
114 |
|
|
115 |
12 |
final BufferedImage res = op.apply(src, null); |
116 |
11 |
write(String.format("%dx%x-to-%dx%d", maxWidth, maxHeight, expectedWidth, expectedHeight), res, BASIC_JPEG); |
117 |
|
|
118 |
11 |
assertEquals(expectedWidth, res.getWidth()); |
119 |
11 |
assertEquals(expectedHeight, res.getHeight()); |
120 |
|
} |
121 |
|
} |