1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.common.api; 18 19 import com.android.ide.common.api.Point; 20 21 import junit.framework.TestCase; 22 23 public class PointTest extends TestCase { 24 25 @Override setUp()26 protected void setUp() throws Exception { 27 super.setUp(); 28 } 29 testPointIntInt()30 public final void testPointIntInt() { 31 Point p = new Point(1, 2); 32 assertEquals(1, p.x); 33 assertEquals(2, p.y); 34 35 p = new Point(-3, -4); 36 assertEquals(-3, p.x); 37 assertEquals(-4, p.y); 38 } 39 testSet()40 public final void testSet() { 41 Point p = new Point(1, 2); 42 assertEquals(1, p.x); 43 assertEquals(2, p.y); 44 45 p.set(-3, -4); 46 assertEquals(-3, p.x); 47 assertEquals(-4, p.y); 48 } 49 testPointPoint()50 public final void testPointPoint() { 51 Point p = new Point(1, 2); 52 Point p2 = new Point(p); 53 54 assertNotSame(p, p2); 55 assertEquals(p, p2); 56 } 57 testPointPoint_Null()58 public final void testPointPoint_Null() { 59 // Constructing a point with null throws an NPE 60 try { 61 new Point(null); 62 } catch (NullPointerException ignore) { 63 return; // success 64 } 65 66 fail("new Point(null) failed to throew NullPointerException"); 67 } 68 testCopy()69 public final void testCopy() { 70 Point p = new Point(1, 2); 71 Point p2 = p.copy(); 72 73 assertNotSame(p, p2); 74 assertEquals(p, p2); 75 } 76 testOffsetBy()77 public final void testOffsetBy() { 78 Point p = new Point(1, 2); 79 Point p2 = p.offsetBy(3, 4); 80 81 assertSame(p, p2); 82 assertEquals(1+3, p.x); 83 assertEquals(2+4, p.y); 84 } 85 testEquals_Null()86 public final void testEquals_Null() { 87 Point p = new Point(1, 2); 88 assertFalse(p.equals(null)); 89 } 90 testEquals_UnknownObject()91 public final void testEquals_UnknownObject() { 92 Point p = new Point(1, 2); 93 assertFalse(p.equals(new Object())); 94 } 95 testEquals_Point()96 public final void testEquals_Point() { 97 Point p = new Point(1, 2); 98 Point p1 = new Point(1, 2); 99 Point p2 = new Point(-3, -4); 100 101 assertNotSame(p1, p); 102 assertTrue(p.equals(p1)); 103 104 assertFalse(p.equals(p2)); 105 } 106 testHashCode()107 public final void testHashCode() { 108 Point p = new Point(1, 2); 109 Point p1 = new Point(1, 2); 110 Point p2 = new Point(-3, -4); 111 112 assertNotSame(p1, p); 113 assertEquals(p1.hashCode(), p.hashCode()); 114 115 assertFalse(p2.hashCode() == p.hashCode()); 116 } 117 testToString()118 public final void testToString() { 119 Point p = new Point(1, 2); 120 assertEquals("Point [1x2]", p.toString()); 121 } 122 123 } 124