Package org.asmatron.messengine.action

Source Code of org.asmatron.messengine.action.TestDefaultCommandEngine

package org.asmatron.messengine.action;

import static org.junit.Assert.assertTrue;

import java.util.concurrent.atomic.AtomicBoolean;

import org.asmatron.messengine.action.ActionHandler;
import org.asmatron.messengine.action.ActionObject;
import org.asmatron.messengine.action.ActionId;
import org.asmatron.messengine.action.DuplicateActionHandlerException;
import org.asmatron.messengine.engines.DefaultActionDelegate;
import org.asmatron.messengine.testing.support.TestActionDelegate;
import org.junit.Test;


public class TestDefaultCommandEngine {
  public static final ActionId<DemoCommandObject> cType = new ActionId<DemoCommandObject>("c");

  @Test
  public void testeamesta() throws Exception {
    DefaultActionDelegate engine = new TestActionDelegate();
    final AtomicBoolean handled = new AtomicBoolean(false);

    engine.addActionHandler(cType, new ActionHandler<DemoCommandObject>() {
      @Override
      public void handle(DemoCommandObject arg) {
        handled.set(true);
      }
    });
    engine.send(cType.create(new DemoCommandObject()));
    assertTrue(handled.get());
  }

  @Test(expected = DuplicateActionHandlerException.class)
  public void shouldNotAddTwoHandlers() throws Exception {
    DefaultActionDelegate engine = new TestActionDelegate();

    engine.addActionHandler(cType, new ActionHandler<DemoCommandObject>() {
      @Override
      public void handle(DemoCommandObject arg) {
      }
    });
    engine.addActionHandler(cType, new ActionHandler<DemoCommandObject>() {
      @Override
      public void handle(DemoCommandObject arg) {
      }
    });
  }
}

class DemoCommandObject extends ActionObject {
}
TOP

Related Classes of org.asmatron.messengine.action.TestDefaultCommandEngine

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.