View Javadoc

1   package com.atlassian.selenium.visualcomparison.test;
2   
3   import java.util.ArrayList;
4   import org.junit.Test;
5   import junit.framework.Assert;
6   import com.atlassian.selenium.visualcomparison.utils.BoundingBox;
7   
8   public class TestBoundingBox 
9   {
10  	@Test
11  	public void testMarginsInsideImage ()
12  	{
13  		BoundingBox box = new BoundingBox (100, 200, 300, 400);
14  		Assert.assertEquals("Box's left margin should be correct", 75, box.getMarginLeft());
15  		Assert.assertEquals("Box's top margin should be correct", 175, box.getMarginTop());
16  		Assert.assertEquals("Box's right margin should be correct", 325, box.getMarginRight(500));
17  		Assert.assertEquals("Box's bottom margin should be correct", 425, box.getMarginBottom(500));
18  	}
19  	
20  	@Test
21  	public void testMarginsOutsideImage ()
22  	{
23  		BoundingBox box = new BoundingBox (10, 15, 100, 200);
24  		Assert.assertEquals("Box's left margin should be correct", 0, box.getMarginLeft());
25  		Assert.assertEquals("Box's top margin should be correct", 0, box.getMarginTop());
26  		Assert.assertEquals("Box's right margin should be correct", 110, box.getMarginRight(110));
27  		Assert.assertEquals("Box's bottom margin should be correct", 210, box.getMarginBottom(210));
28  	}
29  	
30  	@Test
31  	public void testBoxMerging ()
32  	{
33  		ArrayList<BoundingBox> boxes = new ArrayList<BoundingBox> ();
34  		boxes.add (new BoundingBox (10, 10, 20, 20));
35  		boxes.add (new BoundingBox (45, 45, 50, 50));
36  		
37  		BoundingBox.mergeOverlappingBoxes(boxes);
38  		Assert.assertEquals("Boxes should be merged into one", 1, boxes.size());
39  		BoundingBox box = boxes.get(0);
40  		Assert.assertEquals("Bounding box 1 left should be correct", 10, box.getLeft());
41  		Assert.assertEquals("Bounding box 1 top should be correct", 10, box.getTop());
42  		Assert.assertEquals("Bounding box 1 right should be correct", 50, box.getRight());
43  		Assert.assertEquals("Bounding box 1 bottom should be correct", 50, box.getBottom());
44  	}
45  	
46  	@Test
47  	public void testBoxesNotMerged ()
48  	{
49  		ArrayList<BoundingBox> boxes = new ArrayList<BoundingBox> ();
50  		boxes.add (new BoundingBox (10, 10, 20, 20));
51  		boxes.add (new BoundingBox (46, 46, 50, 50));
52  		
53  		BoundingBox.mergeOverlappingBoxes(boxes);
54  		Assert.assertEquals("Boxes should not be merged", 2, boxes.size());
55  		BoundingBox box1 = boxes.get(0);
56  		Assert.assertEquals("Bounding box 1 left should be correct", 10, box1.getLeft());
57  		Assert.assertEquals("Bounding box 1 top should be correct", 10, box1.getTop());
58  		Assert.assertEquals("Bounding box 1 right should be correct", 20, box1.getRight());
59  		Assert.assertEquals("Bounding box 1 bottom should be correct", 20, box1.getBottom());
60  		BoundingBox box2 = boxes.get(1);
61  		Assert.assertEquals("Bounding box 2 left should be correct", 46, box2.getLeft());
62  		Assert.assertEquals("Bounding box 2 top should be correct", 46, box2.getTop());
63  		Assert.assertEquals("Bounding box 2 right should be correct", 50, box2.getRight());
64  		Assert.assertEquals("Bounding box 2 bottom should be correct", 50, box2.getBottom());		
65  	}
66  	
67  	@Test
68  	public void testSingleLineBoxDeletion ()
69  	{
70  		ArrayList<BoundingBox> boxes = new ArrayList<BoundingBox> ();
71  		boxes.add (new BoundingBox (10, 10, 20, 20));
72  		boxes.add (new BoundingBox (30, 30, 30, 50));
73  		boxes.add (new BoundingBox (30, 30, 50, 30));
74  		
75  		BoundingBox.deleteSingleLineBoxes(boxes);
76  		
77  		Assert.assertEquals("One box should be left after removing single-line boxes", 1, boxes.size());
78  		BoundingBox box = boxes.get(0);
79  		Assert.assertEquals("Bounding box left should be correct", 10, box.getLeft());
80  		Assert.assertEquals("Bounding box top should be correct", 10, box.getTop());
81  		Assert.assertEquals("Bounding box right should be correct", 20, box.getRight());
82  		Assert.assertEquals("Bounding box bottom should be correct", 20, box.getBottom());		
83  	}
84  }