Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9d853130c98399eaf2252b9f52fc212d20ad8c9f (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
/*******************************************************************************
 * Copyright (c) 2008, 2009 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.core;

import java.util.Iterator;
import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

/**
 * @since 3.5
 */
public class OrderedPropertiesTest extends AbstractProvisioningTest {

	public void test_249125() {
		OrderedProperties one = new OrderedProperties();
		OrderedProperties two = new OrderedProperties();
		assertEquals("1.0", one, two);

		one = new OrderedProperties();
		two = new OrderedProperties(1);
		assertEquals("1.1", one, two);

		one = new OrderedProperties(1);
		two = new OrderedProperties();
		assertEquals("1.2", one, two);
	}

	/**
	 * Ordered properties guarantees that iteration order is the same as the 
	 * insertion order. This test verifies the claim is true.
	 */
	public void testIterationOrder() {
		//asserts that iteration always occurs in insertion order
		OrderedProperties props = new OrderedProperties();
		props.setProperty("one", "one");
		props.setProperty("two", "two");
		for (Iterator it = props.keySet().iterator(); it.hasNext();) {
			assertEquals("one", it.next());
			assertEquals("two", it.next());
		}
		props = new OrderedProperties();
		props.setProperty("two", "two");
		props.setProperty("one", "one");
		for (Iterator it = props.keySet().iterator(); it.hasNext();) {
			assertEquals("two", it.next());
			assertEquals("one", it.next());
		}

		//removing and re-adding a property should move it to the back of the insertion order
		props.remove("two");
		props.setProperty("two", "two");
		for (Iterator it = props.keySet().iterator(); it.hasNext();) {
			assertEquals("one", it.next());
			assertEquals("two", it.next());
		}
	}
}

Back to the top