Package com.sirenian.hellbound.util

Source Code of com.sirenian.hellbound.util.ListenerSetBehaviour

package com.sirenian.hellbound.util;

import org.jbehave.core.minimock.UsingMiniMock;
import org.jbehave.core.mock.Mock;

public class ListenerSetBehaviour extends UsingMiniMock {

  public void shouldPerformCommandOnAddedListeners() throws Exception {

    ListenerSet list = new ListenerSet();

    Mock listener = mock(WibblableListener.class);
    listener.expects("wibble");

    list.addListener((Listener) listener);

    list.notifyListeners(new WibblyNotifier());

    verifyMocks();
  }
 
  public void shouldNotNotifyRemovedListeners() throws Exception {
    ListenerSet list = new ListenerSet();

    Mock listener = mock(WibblableListener.class);
    listener.expects("wibble").never();
   
    list.addListener((Listener) listener);
    list.removeListener((Listener) listener);

    list.notifyListeners(new WibblyNotifier());

    verifyMocks();   
  }

  public interface WibblableListener extends Listener {
    public void wibble();
  }

  public class WibblyNotifier implements ListenerNotifier {
    public void notify(Listener listener) {
      ((WibblableListener) listener).wibble();
    }
  }
}
TOP

Related Classes of com.sirenian.hellbound.util.ListenerSetBehaviour

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.