Package

Source Code of StateObserversTests

import static org.junit.Assert.assertTrue;

import java.util.List;
import java.util.Set;

import javax.naming.InvalidNameException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import easysm.datatypes.Expr;
import easysm.datatypes.Name;
import easysm.datatypes.information.EventInfo;
import easysm.datatypes.information.ParameterInfo;
import easysm.datatypes.information.ProjectInfo;
import easysm.datatypes.information.StateObserverInfo;
import easysm.executors.Main;
import easysm.factories.SetFactory;
import easysm.stores.StateObserver;
import easysm.stores.Type;

/**
* @author Federica Lupi
* @author Marta Semeria
*/
public class StateObserversTests
{
  Main main;
  Name soPine;
  Name soIffy;

  @Before
  public void setUp()
  {
    main = new Main(false);
    Name name = null;
    try {
      name = new Name("Test");
      soPine = new Name("Pine");
      soIffy = new Name("Iffy");
    } catch (InvalidNameException e) {
      //
    }
    ProjectInfo projectInfo = new ProjectInfo(name, "Test", "Test");
    main.doNewProject(projectInfo);
  }

  @After
  public void tearDown()
  {
    main = null;
  }

  @Test
  public void Main_doAddStateObserver_OneValidSo()
  {
    StateObserverInfo soInfo = new StateObserverInfo(soPine, Type.INTEGER, null);
    main.doAddStateObserver(soInfo);
    List<StateObserver> soSet = main.stateObservers().soList();
    assertTrue(soSet.size() == 2);
    assertTrue(soSet.contains(new StateObserver(soInfo)));
  }

  @Test
  public void Main_doAddStateObserver_WithSameNameOfEvent()
  {
    Set<ParameterInfo> params = SetFactory.createSet(ParameterInfo.class);
    main.doAddEvent(new EventInfo(soIffy, params));
    main.doAddStateObserver(new StateObserverInfo(soIffy, Type.INTEGER, null));
    List<StateObserver> soSet = main.stateObservers().soList();
    assertTrue(soSet.size() == 1);
  }

  @Test
  public void Main_doUpdateStateObserver_OneValidStateObserver()
  {
    main.doAddStateObserver(new StateObserverInfo(soIffy, Type.INTEGER, null));
    List<StateObserver> soSet = main.stateObservers().soList();
    StateObserver so = null;
    for (StateObserver s : soSet) {
      if (s.name().equals(soIffy))
        so = s;
    }
    StateObserverInfo soInfo = new StateObserverInfo(soPine, Type.BOOLEAN, null);
    main.doUpdateStateObserver(so, soInfo);
    assertTrue(soSet.size() == 2);
    assertTrue(so.name().equals(soPine));
    assertTrue(so.type().equals(Type.BOOLEAN));
    assertTrue(so.invariant().equals(Expr.EMPTY));
  }

  @Test
  public void doDeleteStateObserver()
  {
    main.doAddStateObserver(new StateObserverInfo(soIffy, Type.INTEGER, null));
    StateObserver soToDelete = main.stateObservers().soList().get(1);
    main.doDeleteStateObserver(soToDelete);
    assertTrue(main.stateObservers().soList().size() == 1);
  }

  @Test
  public void doAddStateObserver_OneValidInvariant()
  {
    Expr e = new Expr("Pine");
    StateObserverInfo soInfo = new StateObserverInfo(soPine, Type.INTEGER, e);
    StateObserver so = new StateObserver(soInfo);
    main.doAddStateObserver(soInfo);
    assertTrue(so.invariant().equals(e));
  }

  @Test
  public void doUpdateStateObserver_changeInvariant()
  {
    Expr e = new Expr("Pine");
    StateObserverInfo soInfo = new StateObserverInfo(soPine, Type.INTEGER, e);
    main.doAddStateObserver(soInfo);
    StateObserver so = new StateObserver(soInfo);
    Expr newE = new Expr("Pino");
    StateObserverInfo newSoInfo = new StateObserverInfo(soPine, Type.INTEGER, newE);
    main.doUpdateStateObserver(so, newSoInfo);
    assertTrue(so.name().equals(soPine));
    assertTrue(so.type().equals(Type.INTEGER));
    assertTrue(so.invariant().equals(newE));
  }

  public void doUpdateStateObserver_OneNullInvariant()
  {
    Expr e = new Expr("Pine");
    StateObserverInfo soInfo = new StateObserverInfo(soPine, Type.INTEGER, e);
    main.doAddStateObserver(soInfo);
    StateObserver so = new StateObserver(soInfo);
    StateObserverInfo newSoInfo = new StateObserverInfo(soPine, Type.INTEGER, Expr.EMPTY);
    main.doUpdateStateObserver(so, newSoInfo);
    assertTrue(so.name().equals(soPine));
    assertTrue(so.type().equals(Type.INTEGER));
    assertTrue(so.invariant().equals(Expr.EMPTY));
  }

  /*
   * The iffy pine is on the table.
   * Wait, a whole iffy pine cannot be on a table.
   * And... How the hell can a pine be damn iffy?
   * Why? How can you say that? I'm a little iffy about that.
   * Look, Mrs Eclipse does not know the word iffy! How stupid i
   * Why cannot you write?
   * Eclipse hit me in the balls... It hurts...
   * Yep, I'm not iffy about that!
   */
TOP

Related Classes of StateObserversTests

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.