Search in sources :

Example 1 with WrongTypeException

use of net.grandcentrix.tray.core.WrongTypeException in project tray by grandcentrix.

the class ReadDifferentFormat method testReadNullStringAsWrongType.

public void testReadNullStringAsWrongType() throws Exception {
    assertEquals("default", mPref.getString(KEY, "default"));
    mPref.put(KEY, null);
    final TrayItem pref = mPref.getPref(KEY);
    assertNotNull(pref);
    assertEquals(null, pref.value());
    assertEquals(null, mPref.getString(KEY));
    assertEquals(false, mPref.getBoolean(KEY));
    try {
        assertEquals(0.0f, mPref.getFloat(KEY));
        fail();
    } catch (WrongTypeException e) {
        assertTrue(e.getMessage().contains("Float"));
        assertTrue(e.getMessage().contains("null"));
    }
    try {
        assertEquals(0l, mPref.getLong(KEY));
        fail();
    } catch (WrongTypeException e) {
        assertTrue(e.getMessage().contains("Long"));
        assertTrue(e.getMessage().contains("null"));
    }
    try {
        assertEquals(0, mPref.getInt(KEY));
        fail();
    } catch (WrongTypeException e) {
        assertTrue(e.getMessage().contains("Integer"));
        assertTrue(e.getMessage().contains("null"));
    }
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem) WrongTypeException(net.grandcentrix.tray.core.WrongTypeException)

Aggregations

TrayItem (net.grandcentrix.tray.core.TrayItem)1 WrongTypeException (net.grandcentrix.tray.core.WrongTypeException)1