2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
2008-06-29 13:38:57 -04:00
|
|
|
import java.util.ArrayList;
|
2008-06-09 14:41:06 -04:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
2009-03-08 14:41:11 -04:00
|
|
|
import net.sourceforge.tuned.PreferencesMap.SimpleAdapter;
|
|
|
|
|
2008-06-09 14:41:06 -04:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
public class PreferencesListTest {
|
|
|
|
|
|
|
|
private static Preferences root;
|
|
|
|
private static Preferences strings;
|
|
|
|
private static Preferences numbers;
|
|
|
|
private static Preferences temp;
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUpBeforeClass() throws Exception {
|
2008-06-29 13:38:57 -04:00
|
|
|
root = Preferences.userRoot().node("junit-test");
|
2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
strings = root.node("strings");
|
|
|
|
strings.put("0", "Rei");
|
|
|
|
strings.put("1", "Firefly");
|
|
|
|
strings.put("2", "Roswell");
|
|
|
|
strings.put("3", "Angel");
|
|
|
|
strings.put("4", "Dead like me");
|
|
|
|
strings.put("5", "Babylon");
|
|
|
|
|
|
|
|
numbers = root.node("numbers");
|
|
|
|
numbers.putInt("0", 4);
|
|
|
|
numbers.putInt("1", 5);
|
|
|
|
numbers.putInt("2", 2);
|
|
|
|
|
|
|
|
temp = root.node("temp");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
public static void tearDownAfterClass() throws Exception {
|
|
|
|
root.removeNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void get() {
|
2009-03-08 14:41:11 -04:00
|
|
|
List<String> list = PreferencesList.map(strings);
|
2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
assertEquals("Rei", list.get(0));
|
|
|
|
assertEquals("Roswell", list.get(2));
|
|
|
|
assertEquals("Babylon", list.get(5));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
2008-06-29 13:38:57 -04:00
|
|
|
public void add() {
|
2009-03-08 14:41:11 -04:00
|
|
|
List<Integer> list = PreferencesList.map(numbers, SimpleAdapter.forClass(Integer.class));
|
2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
list.add(3);
|
|
|
|
|
|
|
|
assertEquals("3", numbers.get("3", null));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void remove() {
|
|
|
|
|
2008-06-29 13:38:57 -04:00
|
|
|
ArrayList<String> compareValues = new ArrayList<String>();
|
|
|
|
|
|
|
|
compareValues.add("Gladiator 1");
|
|
|
|
compareValues.add("Gladiator 2");
|
|
|
|
compareValues.add("Gladiator 3");
|
|
|
|
compareValues.add("Gladiator 4");
|
|
|
|
compareValues.add("Gladiator 5");
|
|
|
|
|
2009-03-08 14:41:11 -04:00
|
|
|
List<String> prefs = PreferencesList.map(temp);
|
2008-06-29 13:38:57 -04:00
|
|
|
prefs.addAll(compareValues);
|
|
|
|
|
|
|
|
for (int index : new int[] { 4, 0, 1 }) {
|
|
|
|
prefs.remove(index);
|
|
|
|
compareValues.remove(index);
|
|
|
|
|
|
|
|
assertArrayEquals(compareValues.toArray(), prefs.toArray());
|
|
|
|
}
|
2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void setEntry() {
|
2009-03-08 14:41:11 -04:00
|
|
|
List<String> list = PreferencesList.map(strings);
|
2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
list.set(3, "Buffy");
|
|
|
|
|
|
|
|
assertEquals(strings.get("3", null), "Buffy");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void toArray() throws Exception {
|
2009-03-08 14:41:11 -04:00
|
|
|
List<String> list = PreferencesList.map(strings);
|
2008-06-09 14:41:06 -04:00
|
|
|
|
|
|
|
assertArrayEquals(list.subList(0, 3).toArray(), new Object[] { "Rei", "Firefly", "Roswell" });
|
|
|
|
}
|
|
|
|
}
|