Package test

Source Code of test.DependencyResolverTest

package test;

import static org.junit.Assert.*;

import java.util.Vector;

import ass.*;

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

import ass.DependencyResolver;
import ass.Project;

public class DependencyResolverTest {

  private DependencyResolver dep;
  private Board b;
  private Project p1;
  private Project p2;
  private Project p3;
  //private ProjectManager man;

  /**
   * @throws Exception in case Dependency Resolver not exist
   */
  @Before
  public void setUp() throws Exception {
    final int i=7,j=20,k=34,w=40;
    this.dep = new DependencyResolver("man",i);
    Vector<Integer> projectDependenciesList = new Vector<Integer>();
    projectDependenciesList.add(1);
    projectDependenciesList.add(2);

    Vector<Resource> res = new Vector<Resource>();

    Vector<Integer> dependenciesOfP2 = new Vector<Integer>();
    this.p1 = new Project(i, j, "gui", "man", projectDependenciesList, res, this.b);
    this.p2 = new Project(k, w, "system", "Gal", dependenciesOfP2, res, this.b);
  }

  /**
   * @throws Exception t
   */
  @After
  public void tearDown() throws Exception {
  }


  /**
   * @preconditions:   1. The project list of the manager is initialized.
   *          2. the project we want to add does not exist on the list
   *
   * @postconditions:  1. The project that we added is on the manager's project list
   * }          2. the size is bigger.
   */
  @Test
  public void testAddProjectToDependencyList() {
    assertEquals(true, this.dep.getProjectList() != null);
    assertTrue(this.dep.getProjectList().contains(this.p1) == false);

    //post
    int currentsize = this.dep.getProjectList().size();
    this.dep.addProjectToDependencyList(this.p1);
    assertTrue((this.dep.getProjectList().contains(this.p1)) == true);
    assertTrue (this.dep.getProjectList().size() == (currentsize+1));
  }

  /**
   * @preconditions:   1. The project is actually completed - the status of the project is "finished"
   *                 and currentProjectSize=0.
   *           2. The project is currently on the manager's project list, which means that the
   *                 addProjectToDependencyList method was applied on the project, and all it's preconditions
   *                 are also valid.
   *
   * @postconditions:  1. The project that we finalized is no longer the the manager's project list
   *           2. All the projects that the finalized project appears on their dependency list are updated.
   */
  @Test
  public void testFinalizeProject() {
  //  assertTrue(this.p1.getCurrentProjectSize() == 0);
  //  assertTrue(this.p1.getStatus().equals("finished") == true);
  //  assertTrue((this.dep.getProjectList().contains(this.p1)) == true);

    //post
    this.dep.addProjectToDependencyList(this.p1);
    try {
    this.dep.finalizeProject(this.p1);}
    catch (Exception e){assert(false);}
    assert((this.dep.getProjectList().contains(this.p1)) == false);

  //  boolean hasProjectOnList = false;
  //  for (int i=0; i<this.dep.getListOfAllProjects().size() & !hasProjectOnList ; i++){
  //    if ( this.dep.getListOfAllProjects().get(i).containsDependentProject(this.p1) == true )
  //      hasProjectOnList = true;
  //  }
  //  assertTrue (hasProjectOnList);
  }

  /**
   * @preconditions:  1. The project list of the manager is initialized.
   *
   * @postconditions:  1. The returned project is in status "not published yet", currentSize = size.
   *           2. The returned project has no dependencies. (also check that if we have several
   *              projects on the list - the one returned is the project with no dependencies).
   */
  @Test
  public void testGetProjectToPublish() {
    assert(this.dep.getProjectList() != null);
    this.dep.addProjectToDependencyList(this.p1);
    this.dep.addProjectToDependencyList(this.p2);

    //post
    try {
      this.p3 = this.dep.getProjectToPublish();
    }
    catch (InterruptedException e) {
      e.printStackTrace();
    }
    assertTrue( this.p3.getCurrentProjectSize() == this.p3.getProjectSize() );
    assertTrue(this.p3.getCurrentProjectSize() == this.p3.getProjectSize());
    assertTrue(this.p3.getDependencies().isEmpty() == true);
    assertTrue(this.p3.getID() == this.p2.getID());
  }

  /**
   * @preconditions:  1. The project list of the manager is initialized.
   *           2. The project is on the manager's list.
   *
   * @postconditions:  1. the project list does not contain the removed project.
   */
  @Test
  public void testRemoveProject() {
    assertTrue(this.dep.getProjectList() != null);
    this.dep.addProjectToDependencyList(this.p1);
    assertTrue((this.dep.getProjectList().contains(this.p1)) == true);

    //post
    this.dep.removeProject(this.p1);
    assertTrue( (this.dep.removeProject(this.p2)) == false );
    assertTrue( this.dep.getProjectList().contains(this.p1)== false );
  }
}
TOP

Related Classes of test.DependencyResolverTest

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.