Skip to main content
summaryrefslogtreecommitdiffstats
blob: ea91ac9f7cdba7b8a5532be2e4827e3c957f1a52 (plain) (blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2008, 2010 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;

import junit.framework.TestCase;

import org.eclipse.jpt.common.utility.internal.SimpleObjectReference;

@SuppressWarnings("nls")
public class SimpleObjectReferenceTests extends TestCase {

	public SimpleObjectReferenceTests(String name) {
		super(name);
	}

	public void testGetValue() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertNull(or.getValue());
		or.setValue("foo");
		assertEquals("foo", or.getValue());
	}

	public void testValueEqualsObject() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertTrue(or.valueEquals(null));
		assertFalse(or.valueEquals("foo"));

		or.setValue("foo");
		assertFalse(or.valueEquals(null));
		assertTrue(or.valueEquals("foo"));
	}

	public void testValueNotEqualObject() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertFalse(or.valueNotEqual(null));
		assertTrue(or.valueNotEqual("foo"));

		or.setValue("foo");
		assertTrue(or.valueNotEqual(null));
		assertFalse(or.valueNotEqual("foo"));
	}

	public void testIsNull() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertTrue(or.isNull());
		or.setValue("foo");
		assertFalse(or.isNull());
	}

	public void testIsNotNull() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertFalse(or.isNotNull());
		or.setValue("foo");
		assertTrue(or.isNotNull());
	}

	public void testSetNull() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertNull(or.getValue());
		or.setValue("foo");
		assertEquals("foo", or.getValue());
		or.setNull();
		assertNull(or.getValue());
	}

	public void testClone() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>("foo");
		@SuppressWarnings("cast")
		SimpleObjectReference<String> clone = (SimpleObjectReference<String>) or.clone();
		assertEquals("foo", clone.getValue());
		assertNotSame(or, clone);
	}

	public void testToString() {
		SimpleObjectReference<String> or = new SimpleObjectReference<String>();
		assertEquals("[null]", or.toString());
		or.setValue("foo");
		assertEquals("[foo]", or.toString());
	}

}

Back to the top