1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00
filebot/test/net/sourceforge/tuned/PreferencesListTest.java
Reinhard Pointner d1775cf1b4 * added number-pattern similarity metric
* improved name-matching, normalizing of names
* unit-test for new similarity metrics
* improved PreferencesList
* added EventList->List synchronizer
* included GlazedLists in build
2008-06-29 17:38:57 +00:00

113 lines
2.4 KiB
Java

package net.sourceforge.tuned;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.prefs.Preferences;
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 {
root = Preferences.userRoot().node("junit-test");
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() {
List<String> list = PreferencesList.map(strings, String.class);
assertEquals("Rei", list.get(0));
assertEquals("Roswell", list.get(2));
assertEquals("Babylon", list.get(5));
}
@Test
public void add() {
List<Integer> list = PreferencesList.map(numbers, Integer.class);
list.add(3);
assertEquals("3", numbers.get("3", null));
}
@Test
public void remove() {
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");
List<String> prefs = PreferencesList.map(temp, String.class);
prefs.addAll(compareValues);
for (int index : new int[] { 4, 0, 1 }) {
prefs.remove(index);
compareValues.remove(index);
assertArrayEquals(compareValues.toArray(), prefs.toArray());
}
}
@Test
public void setEntry() {
List<String> list = PreferencesList.map(strings, String.class);
list.set(3, "Buffy");
assertEquals(strings.get("3", null), "Buffy");
}
@Test
public void toArray() throws Exception {
List<String> list = PreferencesList.map(strings, String.class);
assertArrayEquals(list.subList(0, 3).toArray(), new Object[] { "Rei", "Firefly", "Roswell" });
}
}