Search in sources :

Example 6 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testSetMultipleChoiceOption_3args_int.

@Test
public void testSetMultipleChoiceOption_3args_int() {
    UserPreferencesManager m = new TestJmriUserPreferencesManager();
    m.setSaveAllowed(false);
    m.setMultipleChoiceOption(strClass, "item1", "value1");
    HashMap<Integer, String> options = new HashMap<>();
    options.put(1, "test1");
    options.put(2, "test2");
    Assert.assertEquals(0, m.getMultipleChoiceOption(strClass, "item1"));
    m.setMessageItemDetails(strClass, "item1", "description1", options, 0);
    Assert.assertEquals(0, m.getMultipleChoiceOption(strClass, "item1"));
    m.setMultipleChoiceOption(strClass, "item1", 1);
    Assert.assertEquals(1, m.getMultipleChoiceOption(strClass, "item1"));
    m.setMultipleChoiceOption(strClass, "item1", 2);
    Assert.assertEquals(2, m.getMultipleChoiceOption(strClass, "item1"));
}
Also used : HashMap(java.util.HashMap) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Example 7 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testGetChoiceDescription.

@Test
public void testGetChoiceDescription() {
    UserPreferencesManager m = new JmriUserPreferencesManager();
    m.setSaveAllowed(false);
    HashMap<Integer, String> options = new HashMap<>();
    options.put(1, "test1");
    Assert.assertNull(m.getChoiceDescription(strClass, "item1"));
    m.setMessageItemDetails(strClass, "item1", "description1", options, 0);
    Assert.assertEquals("description1", m.getChoiceDescription(strClass, "item1"));
}
Also used : HashMap(java.util.HashMap) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Example 8 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testGetChoiceName.

@Test
public void testGetChoiceName() {
    UserPreferencesManager m = new JmriUserPreferencesManager();
    m.setSaveAllowed(false);
    HashMap<Integer, String> options = new HashMap<>();
    options.put(1, "test1");
    Assert.assertNull(m.getChoiceName(strClass, 0));
    m.setMessageItemDetails(strClass, "item1", "description1", options, 0);
    Assert.assertEquals("item1", m.getChoiceName(strClass, 0));
}
Also used : HashMap(java.util.HashMap) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Example 9 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testReadUserPreferences.

@Test
public void testReadUserPreferences() throws IOException {
    JUnitUtil.resetProfileManager(new NullProfile(folder.newFolder(Profile.PROFILE)));
    Point location = new Point(69, 96);
    Dimension windowSize = new Dimension(100, 200);
    UserPreferencesManager m1 = new TestJmriUserPreferencesManager();
    m1.setSaveAllowed(false);
    m1.setProperty(strClass, "test1", "value1");
    m1.setProperty(strClass, "intTest", 42);
    m1.setProperty(strClass, "doubleTest", Math.PI);
    m1.setProperty(strClass, "booleanTest", true);
    m1.setWindowLocation(strClass, location);
    m1.setWindowSize(strClass, windowSize);
    m1.setPreferenceState(strClass, "test2", true);
    m1.setPreferenceState(strClass, "test3", false);
    m1.setSimplePreferenceState(strClass, true);
    m1.setComboBoxLastSelection(strClass, "selection1");
    m1.setSaveAllowed(true);
    File target = new File(new File(new File(ProfileManager.getDefault().getActiveProfile().getPath(), "profile"), NodeIdentity.identity()), "user-interface.xml");
    Assert.assertTrue(target.exists());
    Assert.assertTrue(target.isFile());
    if (log.isDebugEnabled()) {
        Files.lines(target.toPath()).forEach((line) -> log.debug(line));
    }
    JUnitUtil.resetInstanceManager();
    JUnitUtil.resetPreferencesProviders();
    JmriUserPreferencesManager m2 = new JmriUserPreferencesManager();
    m2.readUserPreferences();
    Assert.assertEquals("value1", m2.getProperty(strClass, "test1"));
    Assert.assertEquals(42, m2.getProperty(strClass, "intTest"));
    Assert.assertEquals(Math.PI, m2.getProperty(strClass, "doubleTest"));
    Assert.assertEquals(true, m2.getProperty(strClass, "booleanTest"));
    Assert.assertEquals(location, m2.getWindowLocation(strClass));
    Assert.assertEquals(windowSize, m2.getWindowSize(strClass));
    Assert.assertEquals(true, m2.getPreferenceState(strClass, "test2"));
    Assert.assertEquals(false, m2.getPreferenceState(strClass, "test3"));
    Assert.assertEquals(true, m2.getSimplePreferenceState(strClass));
    Assert.assertEquals("selection1", m2.getComboBoxLastSelection(strClass));
}
Also used : NullProfile(jmri.profile.NullProfile) Point(java.awt.Point) Dimension(java.awt.Dimension) File(java.io.File) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Example 10 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testSetMultipleChoiceOption_3args_String.

@Test
public void testSetMultipleChoiceOption_3args_String() {
    UserPreferencesManager m = new JmriUserPreferencesManager();
    m.setSaveAllowed(false);
    m.setMultipleChoiceOption(strClass, "item1", "value1");
    HashMap<Integer, String> options = new HashMap<>();
    options.put(1, "test1");
    options.put(2, "test2");
    Assert.assertEquals(0, m.getMultipleChoiceOption(strClass, "item1"));
    m.setMessageItemDetails(strClass, "item1", "description1", options, 0);
    Assert.assertEquals(0, m.getMultipleChoiceOption(strClass, "item1"));
    m.setMultipleChoiceOption(strClass, "item1", "test1");
    Assert.assertEquals(1, m.getMultipleChoiceOption(strClass, "item1"));
    m.setMultipleChoiceOption(strClass, "item1", "test2");
    Assert.assertEquals(2, m.getMultipleChoiceOption(strClass, "item1"));
}
Also used : HashMap(java.util.HashMap) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Aggregations

UserPreferencesManager (jmri.UserPreferencesManager)47 Test (org.junit.Test)43 HashMap (java.util.HashMap)10 Dimension (java.awt.Dimension)7 Point (java.awt.Point)5 AppConfigBase (apps.AppConfigBase)2 File (java.io.File)2 JLabel (javax.swing.JLabel)2 RosterGroupSelector (jmri.jmrit.roster.rostergroup.RosterGroupSelector)2 NullProfile (jmri.profile.NullProfile)2 BoxLayout (javax.swing.BoxLayout)1 JCheckBox (javax.swing.JCheckBox)1 JPanel (javax.swing.JPanel)1 ShutDownManager (jmri.ShutDownManager)1