private void addPlayersToGame(
      com.yazino.game.api.GameStatus gameStatus, com.yazino.game.api.GamePlayer... players) {
    Collection<com.yazino.game.api.PlayerAtTableInformation> playerAtTableInformationCollection =
        new ArrayList<>();
    for (com.yazino.game.api.GamePlayer player : players) {
      playerAtTableInformationCollection.add(
          new com.yazino.game.api.PlayerAtTableInformation(
              player, Collections.<String, String>emptyMap()));
      if (table.playerAtTable(player.getId()) == null) {
        if (player.getId().equals(PLAYER_ID)) {
          table.addPlayerToTable(
              new PlayerInformation(
                  PLAYER_ID, PLAYER_NAME, PLAYER_ACCOUNT_ID, BigDecimal.TEN, BigDecimal.ZERO));
        } else if (player.getId().equals(PLAYER1_ID)) {
          table.addPlayerToTable(
              new PlayerInformation(
                  PLAYER1_ID, "player1", PLAYER1_ACCOUNT_ID, BigDecimal.TEN, BigDecimal.ZERO));
        } else if (player.getId().equals(PLAYER2_ID)) {
          table.addPlayerToTable(
              new PlayerInformation(
                  PLAYER2_ID, "player2", PLAYER2_ACCOUNT_ID, BigDecimal.TEN, BigDecimal.ZERO));
        } else {
          table.addPlayerToTable(
              new PlayerInformation(
                  player.getId(),
                  player.getName(),
                  player.getId(),
                  BigDecimal.TEN,
                  BigDecimal.ZERO));
        }
      }
    }

    when(gameRules.getPlayerInformation(gameStatus)).thenReturn(playerAtTableInformationCollection);
  }
示例#2
0
  @Test
  public void shouldPurgeDiskDumpAndRepositoryOlderThanGivenTime()
      throws IOException, ClassNotFoundException, InterruptedException {
    final GregorianCalendar[] cal = new GregorianCalendar[1];
    final TimeProvider timeProvider =
        new TimeProvider() {
          @Override
          public GregorianCalendar cal() {
            GregorianCalendar gregorianCalendar = cal[0];
            return gregorianCalendar == null ? null : (GregorianCalendar) gregorianCalendar.clone();
          }

          @Override
          public Date now() {
            return cal().getTime();
          }
        };
    final EntryRepoFactory factory = new EntryRepoFactory(baseDir, timeProvider);

    cal[0] = new GregorianCalendar(2010, 6, 7, 0, 37, 12);

    SuiteTimeRepo repo = factory.createSuiteTimeRepo("foo", LATEST_VERSION);
    repo.update(new SuiteTimeEntry("foo.bar.Baz", 15));
    repo.update(new SuiteTimeEntry("foo.bar.Quux", 80));

    Collection<SuiteTimeEntry> oldList = repo.list("old");
    assertThat(oldList.size(), is(2));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Baz", 15)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));

    repo.update(new SuiteTimeEntry("foo.bar.Bang", 130));
    repo.update(new SuiteTimeEntry("foo.bar.Baz", 20));

    oldList = repo.list("old");
    assertThat(oldList.size(), is(2));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Baz", 15)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));

    cal[0] = new GregorianCalendar(2010, 6, 9, 0, 37, 12);
    Collection<SuiteTimeEntry> notSoOld = repo.list("not_so_old");
    assertThat(notSoOld.size(), is(3));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Baz", 20)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Bang", 130)));

    repo.update(new SuiteTimeEntry("foo.bar.Foo", 12));

    final Thread exitHook = factory.exitHook();
    exitHook.start();
    exitHook.join();

    cal[0] = new GregorianCalendar(2010, 6, 10, 0, 37, 12);
    factory.purgeVersionsOlderThan(2);

    oldList = repo.list("old");
    assertThat(oldList.size(), is(4));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Baz", 20)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Bang", 130)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Foo", 12)));

    notSoOld = repo.list("not_so_old");
    assertThat(notSoOld.size(), is(3));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Baz", 20)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Bang", 130)));
  }