Skip to content

Commit 96d9e95

Browse files
committed
Update RectangeTest
RND-366
1 parent fe6536d commit 96d9e95

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

kernel/src/test/java/com/itextpdf/kernel/geom/RectangleTest.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.kernel.PdfException;
4646
import com.itextpdf.kernel.pdf.PdfArray;
47-
import com.itextpdf.kernel.pdf.PdfNumber;
4847
import com.itextpdf.test.ExtendedITextTest;
4948
import com.itextpdf.test.annotations.type.UnitTest;
5049
import org.junit.Assert;
@@ -62,7 +61,7 @@ public void rectangleOverlapTest01() {
6261
//Intersection
6362
Rectangle one = new Rectangle(0, 0, 10, 10);
6463
Rectangle two = new Rectangle(5, 5, 5, 5);
65-
Boolean result = one.overlaps(two);
64+
boolean result = one.overlaps(two);
6665
Assert.assertTrue(result);
6766

6867
//envelopment
@@ -85,7 +84,7 @@ public void rectangleOverlapTest02() {
8584
//Top left
8685
Rectangle one = new Rectangle(0, 0, 10, 10);
8786
Rectangle two = new Rectangle(15, 15, 10, 10);
88-
Boolean result = one.overlaps(two);
87+
boolean result = one.overlaps(two);
8988
Assert.assertFalse(result);
9089
//Middle left
9190
one = new Rectangle(0, 0, 10, 10);
@@ -142,7 +141,7 @@ public void envelopTest01() {
142141
//one contains two
143142
Rectangle one = new Rectangle(0, 0, 10, 10);
144143
Rectangle two = new Rectangle(5, 5, 5, 5);
145-
Boolean result = one.contains(two);
144+
boolean result = one.contains(two);
146145
Assert.assertTrue(result);
147146
}
148147

@@ -151,7 +150,7 @@ public void envelopsTest02() {
151150
//two identical rectangles
152151
Rectangle one = new Rectangle(0, 0, 10, 10);
153152
Rectangle two = new Rectangle(0, 0, 10, 10);
154-
Boolean result = one.contains(two);
153+
boolean result = one.contains(two);
155154
Assert.assertTrue(result);
156155

157156
}
@@ -161,7 +160,7 @@ public void envelopsTest03() {
161160
//One intersects two but does not envelop
162161
Rectangle one = new Rectangle(0, 0, 10, 10);
163162
Rectangle two = new Rectangle(5, 5, 10, 10);
164-
Boolean result = one.contains(two);
163+
boolean result = one.contains(two);
165164
Assert.assertFalse(result);
166165
}
167166

@@ -170,22 +169,22 @@ public void envelopsTest04() {
170169
//one and two do not
171170
Rectangle one = new Rectangle(0, 0, 10, 10);
172171
Rectangle two = new Rectangle(-15, -15, 10, 10);
173-
Boolean result = one.contains(two);
172+
boolean result = one.contains(two);
174173
Assert.assertFalse(result);
175174
}
176175

177176
@Test
178177
public void getIntersectionTest01() {
179178
//Cases where there is an intersection rectangle
180179
Rectangle main, second, actual, expected;
181-
Boolean areEqual = true;
180+
boolean areEqual;
182181
main = new Rectangle(2, 2, 8, 8);
183182
//A. Main rectangle is greater in both dimension than second rectangle
184183
second = new Rectangle(4, 8, 4, 4);
185184
//1.Middle top
186185
expected = new Rectangle(4, 8, 4, 2);
187186
actual = main.getIntersection(second);
188-
areEqual = areEqual && (expected.equals(actual));
187+
areEqual = expected.equals(actual);
189188
//2.Middle Right
190189
second.moveRight(4);
191190
expected = new Rectangle(8, 8, 2, 2);
@@ -261,13 +260,13 @@ public void getIntersectionTest01() {
261260
@Test
262261
public void getIntersectionTest02() {
263262
//Cases where the two rectangles do not intersect
264-
Rectangle main, second, actual, expected;
265-
Boolean noIntersection = true;
263+
Rectangle main, second, actual;
264+
boolean noIntersection;
266265
main = new Rectangle(2, 2, 8, 8);
267266
//Top
268267
second = new Rectangle(4, 12, 4, 4);
269268
actual = main.getIntersection(second);
270-
noIntersection = noIntersection && ((actual) == null);
269+
noIntersection = actual == null;
271270
//Right
272271
second = new Rectangle(12, 4, 4, 4);
273272
actual = main.getIntersection(second);
@@ -289,12 +288,12 @@ public void getIntersectionTest03() {
289288
//Edge cases: envelopment
290289
//A equal rectangles
291290
Rectangle main, second, actual, expected;
292-
Boolean areEqual = true;
291+
boolean areEqual;
293292
main = new Rectangle(2, 2, 8, 8);
294293
second = new Rectangle(main);
295294
expected = new Rectangle(main);
296295
actual = main.getIntersection(second);
297-
areEqual = areEqual && (expected.equals(actual));
296+
areEqual = expected.equals(actual);
298297
//B main contains second
299298
main = new Rectangle(2, 2, 8, 8);
300299
second = new Rectangle(4, 4, 4, 4);
@@ -315,13 +314,13 @@ public void getIntersectionTest03() {
315314
public void getIntersectionTest04() {
316315
//Edge case: intersections on edges
317316
Rectangle main, second, actual, expected;
318-
Boolean areEqual = true;
317+
boolean areEqual;
319318
main = new Rectangle(2, 2, 8, 8);
320319
//Top
321320
second = new Rectangle(4, 10, 4, 4);
322321
expected = new Rectangle(4, 10, 4, 0);
323322
actual = main.getIntersection(second);
324-
areEqual = areEqual && (expected.equals(actual));
323+
areEqual = expected.equals(actual);
325324
//Right
326325
second = new Rectangle(10, 4, 4, 4);
327326
expected = new Rectangle(10, 4, 0, 4);
@@ -374,16 +373,19 @@ public void createBoundingRectangleFromQuadPointsTest01() {
374373

375374
}
376375

377-
@Test(expected = PdfException.class)
376+
@Test
378377
public void createBoundingRectangleFromQuadPointsTest02() {
379-
Rectangle actual, expected;
380378
float[] points = {0, 0, 2, 1, 1, 2, -2, 1, 0};
381379
PdfArray quadpoints = new PdfArray(points);
382380

383-
expected = new Rectangle(-2, 0, 4, 2);
384-
actual = Rectangle.createBoundingRectangleFromQuadPoint(quadpoints);
381+
boolean exception = false;
382+
try {
383+
Rectangle.createBoundingRectangleFromQuadPoint(quadpoints);
384+
} catch (PdfException e) {
385+
exception = true;
386+
}
385387

386-
Assert.assertEquals(expected, actual);
388+
Assert.assertTrue(exception);
387389
}
388390

389391
@Test
@@ -399,18 +401,19 @@ public void createBoundingRectanglesFromQuadPointsTest01() {
399401
Assert.assertArrayEquals(expected.toArray(), actual.toArray());
400402
}
401403

402-
@Test(expected = PdfException.class)
404+
@Test
403405
public void createBoundingRectanglesFromQuadPointsTest02() {
404-
List<Rectangle> actual, expected;
405406
float[] points = {0, 0, 2, 1, 1, 2, -2, 1,
406407
0, -1, 2, 0, 1, 1, -2, 0,
407408
1};
408409
PdfArray quadpoints = new PdfArray(points);
409-
expected = new ArrayList<Rectangle>();
410-
expected.add(new Rectangle(-2, 0, 4, 2));
411-
expected.add(new Rectangle(-2, -1, 4, 2));
412-
actual = Rectangle.createBoundingRectanglesFromQuadPoint(quadpoints);
413-
Assert.assertArrayEquals(expected.toArray(), actual.toArray());
410+
boolean exception = false;
411+
try {
412+
Rectangle.createBoundingRectanglesFromQuadPoint(quadpoints);
413+
} catch (PdfException e) {
414+
exception = true;
415+
}
416+
417+
Assert.assertTrue(exception);
414418
}
415-
416419
}

0 commit comments

Comments
 (0)