/** Test tracks tree expansion listener. */ public final void testTracksTreeExpansionListener() { TracksTreeExpansionListener ad = new TracksTreeExpansionListener(); assertNotNull(ad); { Genre genre = getGenre(); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); ad.treeExpanded(new TreeExpansionEvent("dummy", new TreePath(new GenreNode(genre)))); assertEquals(true, genre.getProperties().get(Const.XML_EXPANDED)); ad.treeCollapsed(new TreeExpansionEvent("dummy", new TreePath(new GenreNode(genre)))); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); } { Artist genre = getArtist(); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); ad.treeExpanded(new TreeExpansionEvent("dummy", new TreePath(new ArtistNode(genre)))); assertEquals(true, genre.getProperties().get(Const.XML_EXPANDED)); ad.treeCollapsed(new TreeExpansionEvent("dummy", new TreePath(new ArtistNode(genre)))); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); } { Album genre = getAlbum(); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); ad.treeExpanded(new TreeExpansionEvent("dummy", new TreePath(new AlbumNode(genre)))); assertEquals(true, genre.getProperties().get(Const.XML_EXPANDED)); ad.treeCollapsed(new TreeExpansionEvent("dummy", new TreePath(new AlbumNode(genre)))); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); } { Year genre = getYear(); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); ad.treeExpanded(new TreeExpansionEvent("dummy", new TreePath(new YearNode(genre)))); assertEquals(true, genre.getProperties().get(Const.XML_EXPANDED)); ad.treeCollapsed(new TreeExpansionEvent("dummy", new TreePath(new YearNode(genre)))); assertNull(genre.getProperties().get(Const.XML_EXPANDED)); } }
/** * Test method for {@link org.jajuk.services.dj.AmbienceManager#load()}. * * @throws Exception the exception */ public final void testLoad() throws Exception { // make sure "UpgradeManager.bFirstSession" is not set { Class<?> c = UpgradeManager.class; Field f = c.getDeclaredField("firstSession"); f.setAccessible(true); f.setBoolean(null, Boolean.FALSE); } assertFalse(UpgradeManager.isFirstSession()); assertEquals(0, AmbienceManager.getInstance().getAmbiences().size()); // first without any key AmbienceManager.getInstance().load(); // creates the 14 default ambiences assertEquals(14, AmbienceManager.getInstance().getAmbiences().size()); // clean out all leftover ambiences from other testing for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) { AmbienceManager.getInstance().removeAmbience(amb.getID()); } assertEquals(0, AmbienceManager.getInstance().getAmbiences().size()); { // remove all leftover properties Properties properties = Conf.getProperties(); Enumeration<Object> e = properties.keys(); while (e.hasMoreElements()) { String sKey = (String) e.nextElement(); if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) { properties.remove(sKey); } } } // then add set some Ambience-items Genre genre1 = GenreManager.getInstance().registerGenre("genre1"); Genre genre2 = GenreManager.getInstance().registerGenre("genre2"); Conf.setProperty( Const.AMBIENCE_PREFIX + "12/myambience", genre1.getID() + "," + genre2.getID()); assertEquals(0, AmbienceManager.getInstance().getAmbiences().size()); { // check all the conditions to find out why it fails in Hudson assertFalse(UpgradeManager.isFirstSession()); Properties properties = Conf.getProperties(); Enumeration<Object> e = properties.keys(); int nMatch = 0; while (e.hasMoreElements()) { String sKey = (String) e.nextElement(); if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) { if (sKey.substring(Const.AMBIENCE_PREFIX.length()).indexOf('/') == -1) { continue; } nMatch++; } } assertEquals(properties.toString(), 1, nMatch); } AmbienceManager.getInstance().load(); assertEquals(1, AmbienceManager.getInstance().getAmbiences().size()); assertNotNull(AmbienceManager.getInstance().getAmbience("12")); // now test with an ambience with invalid format, i.e. only "12", not // "12/name" for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) { AmbienceManager.getInstance().removeAmbience(amb.getID()); } assertEquals(0, AmbienceManager.getInstance().getAmbiences().size()); Conf.setProperty(Const.AMBIENCE_PREFIX + "12", genre1.getID() + "," + genre2.getID()); Conf.removeProperty(Const.AMBIENCE_PREFIX + "12/myambience"); AmbienceManager.getInstance().load(); // now 14 as this could not be loaded and thus the default ones were // loaded... assertEquals(14, AmbienceManager.getInstance().getAmbiences().size()); UpgradeManager.setFirstSession(); AmbienceManager.getInstance().load(); }