Package org.scotlandyard.tests.engine.chat

Source Code of org.scotlandyard.tests.engine.chat.ChatTest

package org.scotlandyard.tests.engine.chat;


import java.util.Date;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.scotlandyard.engine.chat.Chat;
import org.scotlandyard.engine.player.Player;
import org.scotlandyard.impl.engine.GameEngine;
import org.scotlandyard.impl.engine.chat.ChatImpl;
import org.scotlandyard.impl.engine.player.Detective;
import org.scotlandyard.impl.engine.player.MrX;
/**
* TODO add description
*
* @author Hussain Al-Mutawa
* @version 1.0
* @since Sept 2011
*
*/
public class ChatTest {

  private transient static Player detective,mrX;
  private transient static Chat chat;
  private transient static Date before,after;

  @BeforeClass//TODO add description here
  public static void beforeClass() throws Throwable {
//    if(!GameEngine.instance().getChatHistory().isEmpty()){
//                    throw new Exception("why would the game engine chat history have anything yet");
//    }
    before = new Date(System.currentTimeMillis());
    Thread.sleep(300);
    detective = new Detective("detective", "detective@scotlandyard.org");
    mrX = new MrX("detective", "detective@scotlandyard.org");
    chat = ChatImpl.getNewInstance(detective, mrX, "Hello");

    Thread.sleep(300);
    after = new Date(System.currentTimeMillis());
  }

  @Before//TODO add description here
  public final void setUp(){
    Assert.assertEquals(GameEngine.instance().getChatHistory().size(),1);
  }

  @Test//TODO add description here
  public final void testGetFromPlayer() {
    Assert.assertSame(GameEngine.instance().getChatHistory().iterator().next().getFromPlayer(),detective);
  }

  @Test//TODO add description here
  public final void testGetToPlayer() {
    Assert.assertSame(GameEngine.instance().getChatHistory().iterator().next().getToPlayer(),mrX);
  }

  @Test//TODO add description here
  public final void testGetMessage() {
    Assert.assertNotNull(chat.getMessage());
    Assert.assertEquals(chat.getMessage(),"Hello");
  }

  @Test//TODO add description here
  public final void testGetTime() {
    Assert.assertTrue(before.compareTo(chat.getTime())<0);
    Assert.assertTrue( after.compareTo(chat.getTime())>0);
  }

  @Test//TODO add description here
  public final void testIsReceived() {
    Assert.assertFalse(chat.isReceived());
  }

  @Test//TODO add description here
  public final void testSetReceived() {
    chat.setReceived();
    Assert.assertTrue(chat.isReceived());
  }

}
TOP

Related Classes of org.scotlandyard.tests.engine.chat.ChatTest

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.