@Override
 protected void specificSetUp() throws Exception {
   // clean out all leftover ambiences from other testing
   for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) {
     AmbienceManager.getInstance().removeAmbience(amb.getID());
   }
 }
 /**
  * @param sName Ambience name
  * @return registrated ambience or null if no matching name
  */
 public Ambience getAmbienceByName(String sName) {
   for (Ambience ambience : ambiences.values()) {
     if (ambience.getName().equals(sName)) {
       return ambience;
     }
   }
   return null;
 }
 /*
  * (non-Javadoc)
  *
  * @see org.jajuk.ui.Observer#update(java.lang.String)
  */
 public void update(JajukEvent event) {
   JajukEvents subject = event.getSubject();
   if (JajukEvents.STYLE_NAME_CHANGED.equals(subject)) {
     Properties properties = event.getDetails();
     Style old = (Style) properties.get(Const.DETAIL_OLD);
     Style newStyle = (Style) properties.get(Const.DETAIL_NEW);
     // replace style into all styles
     for (Ambience ambience : ambiences.values()) {
       if (ambience.getStyles().contains(old)) {
         ambience.removeStyle(old);
         ambience.addStyle(newStyle);
       }
     }
   }
 }
 /**
  * Gets the transition.
  *
  * @param ambience DOCUMENT_ME
  * @return transition mapping this FROM ambience or null if none maps it
  */
 public Transition getTransition(Ambience ambience) {
   for (Transition transition : transitions) {
     if (CollectionUtils.containsAny(transition.getFrom().getGenres(), ambience.getGenres())) {
       return transition;
     }
   }
   return null;
 }
 /** Perform required operations before exit */
 public void commit() {
   // first, remove all ambiences from configuration
   Properties properties = Conf.getProperties();
   Iterator<Object> it = properties.keySet().iterator();
   while (it.hasNext()) {
     String sKey = (String) it.next();
     if (sKey.startsWith(Const.AMBIENCE_PREFIX)) {
       it.remove();
     }
   }
   // now create and set each ambience
   for (Ambience ambience : ambiences.values()) {
     if (ambience.getStyles().size() > 0) {
       String styles = "";
       for (Style style : ambience.getStyles()) {
         styles += style.getID() + ',';
       }
       styles = styles.substring(0, styles.length() - 1);
       Conf.setProperty(
           Const.AMBIENCE_PREFIX + ambience.getID() + '/' + ambience.getName(), styles);
     }
   }
 }
 /**
  * Register a new ambience
  *
  * @param ambience ambience to register
  */
 public void registerAmbience(Ambience ambience) {
   ambiences.put(ambience.getID(), ambience);
 }
 /**
  * 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();
 }