1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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
17package vogar.target;
18
19import junit.framework.AssertionFailedError;
20import junit.framework.TestCase;
21
22public final class AssertTest extends TestCase {
23
24    public void testAssertEquals() {
25        Object o = new Object();
26        assertEquals(o, o);
27
28        boolean success = false;
29        try {
30            assertEquals(o, new Object());
31            // can't fail(), that throws AssertionFailedError
32        } catch (AssertionFailedError expected) {
33            success = true;
34        }
35        assertTrue(success);
36    }
37
38    public void testAssertEqualsNan() {
39        assertEquals(Double.NaN, Double.NaN, 0.0);
40
41        boolean success = false;
42        try {
43            assertEquals(5, Double.NaN, 0.0);
44            // can't fail(), that throws AssertionFailedError
45        } catch (AssertionFailedError expected) {
46            success = true;
47        }
48        assertTrue(success);
49    }
50
51    public void testAssertEqualsWithDelta() {
52        assertEquals(0.0, 5.0, 5.0);
53
54        boolean success = false;
55        try {
56            assertEquals(0.0, 6.0, 5.0);
57            // can't fail(), that throws AssertionFailedError
58        } catch (AssertionFailedError expected) {
59            success = true;
60        }
61        assertTrue(success);
62    }
63
64    public void testAssertEqualsWithNaNDelta() {
65        assertEquals(0.0, 0.0, Double.NaN);
66
67        boolean success = false;
68        try {
69            assertEquals(0.0, 6.0, Double.NaN);
70            // can't fail(), that throws AssertionFailedError
71        } catch (AssertionFailedError expected) {
72            success = true;
73        }
74        assertTrue(success);
75    }
76
77    public void testAssertSame() {
78        assertSame(this, this);
79
80        boolean success = false;
81        try {
82            assertSame(new Object(), new Object());
83            // can't fail(), that throws AssertionFailedError
84        } catch (AssertionFailedError expected) {
85            success = true;
86        }
87        assertTrue(success);
88    }
89
90    public void testAssertNotSame() {
91        assertNotSame(new Object(), new Object());
92
93        boolean success = false;
94        try {
95            assertNotSame(this, this);
96            // can't fail(), that throws AssertionFailedError
97        } catch (AssertionFailedError expected) {
98            success = true;
99        }
100        assertTrue(success);
101    }
102
103    public void testAssertNull() {
104        assertNull(null);
105
106        boolean success = false;
107        try {
108            assertNull(this);
109            // can't fail(), that throws AssertionFailedError
110        } catch (AssertionFailedError expected) {
111            success = true;
112        }
113        assertTrue(success);
114    }
115
116    public void testAssertNotNull() {
117        assertNotNull(new Object());
118
119        boolean success = false;
120        try {
121            assertNotNull(null);
122            // can't fail(), that throws AssertionFailedError
123        } catch (AssertionFailedError expected) {
124            success = true;
125        }
126        assertTrue(success);
127    }
128}
129