@Before
  public void init() throws IOException {

    ScrabbleSystem.getInstance().destorySystem();
    Board.getInstance().destroyBoard();
    Bag.getInstance().resetTileBag();

    scrabbleSystem = ScrabbleSystem.getInstance();
    board = Board.getInstance();
    factory = new SpecialTileFactory();
    testFactory = new TestFactory();
    dict = new Dict();

    // first player's move
    moveList1 = testFactory.produceMoveList1();
    SpecialTile negativePoints = factory.produce(SpecialTileType.NEGATIVE_POINTS);
    SpecialMove specialMove1 = new SpecialMove(position5, negativePoints);
    specialMoveList1 = new ArrayList<>();
    specialMoveList1.add(specialMove1);

    // second player's move
    moveList2 = testFactory.produceMoveList2();
    specialMoveList2 = new ArrayList<>();

    // initialize game and start
    ArrayList<String> playerNameList = new ArrayList<>();
    playerNameList.add("Bob");
    playerNameList.add("Lucy");
    scrabbleSystem.startGame(playerNameList);
  }
  @Test
  public void timeout() throws Exception {
    TestFactory f = new TestFactory();
    SessionManager<Integer> s = new SessionManager<Integer>(f, TEST_LIFESPAN);
    assertEquals(TEST_LIFESPAN, s.getLifespan());

    SessionHolder<Integer> h = new SessionHolder<Integer>(TEST_USER, TEST_CONTEXT);
    s.put(TEST_SESSION_ID, h);
    assertSame(h, s.get(TEST_SESSION_ID));
    assertEquals(TEST_SESSION_ID, f.getLastSessionId());
    for (int i = 0; i < 10; i++) {
      Thread.sleep(TEST_LIFESPAN / 2);
      assertSame(h, s.get(TEST_SESSION_ID));
    }
    Thread.sleep(TEST_LIFESPAN * 2);
    assertSingleEvent(
        Level.INFO,
        TEST_CATEGORY,
        "Session "
            + TEST_SESSION_ID.toString()
            + " has expired; creation context: "
            + TEST_CONTEXT.toString(),
        TEST_CATEGORY);
    assertNull(s.get(TEST_SESSION_ID));
    assertEquals(TEST_SESSION, f.getLastRemovedSession());
  }
  @Test
  public void basics() throws Exception {
    TestFactory f = new TestFactory();
    SessionManager<Integer> s = new SessionManager<Integer>(f);
    assertSame(f, s.getSessionFactory());
    assertEquals(SessionManager.INFINITE_SESSION_LIFESPAN, s.getLifespan());

    assertNull(s.getServerId());
    s.setServerId(TEST_SERVER_ID);
    assertEquals(TEST_SERVER_ID, s.getServerId());
    s.setServerId(null);
    assertNull(s.getServerId());

    assertNull(s.get(TEST_SESSION_ID));

    SessionHolder<Integer> hD = new SessionHolder<Integer>(TEST_USER, TEST_CONTEXT);
    long time = hD.getLastAccess();
    Thread.sleep(100);
    s.put(TEST_SESSION_ID, hD);
    assertTrue(hD.getLastAccess() > time);
    assertEquals(TEST_SESSION_ID, f.getLastSessionId());

    time = hD.getLastAccess();
    Thread.sleep(100);
    assertSame(hD, s.get(TEST_SESSION_ID));
    assertTrue(hD.getLastAccess() > time);

    SessionHolder<Integer> h = new SessionHolder<Integer>(TEST_USER, TEST_CONTEXT);
    s.put(TEST_SESSION_ID, h);
    assertSame(h, s.get(TEST_SESSION_ID));

    assertNull(s.get(TEST_SESSION_ID_D));
    s.put(TEST_SESSION_ID_D, hD);
    assertSame(hD, s.get(TEST_SESSION_ID_D));
    assertSame(h, s.get(TEST_SESSION_ID));
    assertEquals(TEST_SESSION_ID_D, f.getLastSessionId());

    s.remove(TEST_SESSION_ID);
    assertNull(s.get(TEST_SESSION_ID));
    assertSame(hD, s.get(TEST_SESSION_ID_D));
    assertEquals(TEST_SESSION, f.getLastRemovedSession());

    // Removal of nonexistent session ID.

    s.remove(TEST_SESSION_ID);
  }