@Test
 public void forceNewGameWillRestartTableAndStartNewGame() {
   Map<BigDecimal, BigDecimal> playerIdToAccountIdOverrides = new HashMap<>();
   playerIdToAccountIdOverrides.put(PLAYER_ID, BigDecimal.valueOf(202020));
   com.yazino.game.api.GameStatus status = new GameStatus(new PrintlnStatus());
   com.yazino.game.api.ExecutionResult result =
       new com.yazino.game.api.ExecutionResult.Builder(gameRules, status).build();
   when(gameRules.startNewGame(isA(com.yazino.game.api.GameCreationContext.class)))
       .thenReturn(result);
   when(auditor.newLabel()).thenReturn("X");
   host = gameHost(new InMemoryGameRepository(gameRules));
   table.setTableStatus(TableStatus.closed);
   table.setCurrentGame(null);
   Collection<com.yazino.game.api.PlayerAtTableInformation> playersAtTable =
       Arrays.asList(
           new com.yazino.game.api.PlayerAtTableInformation(
               new com.yazino.game.api.GamePlayer(PLAYER1_ID, null, "One"),
               Collections.<String, String>emptyMap()),
           new com.yazino.game.api.PlayerAtTableInformation(
               new com.yazino.game.api.GamePlayer(PLAYER2_ID, null, "Two"),
               Collections.<String, String>emptyMap()));
   host.forceNewGame(table, playersAtTable, playerIdToAccountIdOverrides);
   ArgumentCaptor<com.yazino.game.api.GameCreationContext> contextCaptor =
       ArgumentCaptor.forClass(com.yazino.game.api.GameCreationContext.class);
   verify(gameRules).startNewGame(contextCaptor.capture());
   assertEquals(TableStatus.open, table.getTableStatus());
   assertEquals(status, table.getCurrentGame());
   assertEquals(playersAtTable, contextCaptor.getValue().getPlayersAtTableInformation());
 }
Ejemplo n.º 2
0
  @Test
  public void getDistinctKeysAndCounts_SortByKeyDescending() {

    Connection connection = null;
    ResultSet resultSet = null;
    try {
      ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true);
      initWithTestData(connectionManager);

      connection = connectionManager.getConnection(null);
      resultSet = DBQueries.getDistinctKeysAndCounts(true, NAME, connection);

      Map<String, Integer> resultSetToMap = resultSetToMap(resultSet);
      assertEquals(3, resultSetToMap.size());

      Iterator<Map.Entry<String, Integer>> entriesIterator = resultSetToMap.entrySet().iterator();

      Map.Entry entry = entriesIterator.next();
      assertEquals("gps", entry.getKey());
      assertEquals(1, entry.getValue());

      entry = entriesIterator.next();
      assertEquals("airbags", entry.getKey());
      assertEquals(1, entry.getValue());

      entry = entriesIterator.next();
      assertEquals("abs", entry.getKey());
      assertEquals(2, entry.getValue());

    } finally {
      DBUtils.closeQuietly(resultSet);
      DBUtils.closeQuietly(connection);
    }
  }
Ejemplo n.º 3
0
  public static <K, V> Map<K, V> resultSetToMap(final ResultSet resultSet) {

    try {
      final Map<K, V> map = new LinkedHashMap<K, V>();

      while (resultSet.next()) {

        K key = (K) resultSet.getObject(1);
        V value = (V) resultSet.getObject(2);

        map.put(key, value);
      }

      return map;
    } catch (Exception e) {
      throw new IllegalStateException("Unable to transform the resultSet into a Map", e);
    }
  }
Ejemplo n.º 4
0
  @Test
  public void getDistinctKeysAndCounts() {

    Connection connection = null;
    ResultSet resultSet = null;
    try {
      ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true);
      initWithTestData(connectionManager);

      connection = connectionManager.getConnection(null);
      resultSet = DBQueries.getDistinctKeysAndCounts(false, NAME, connection);

      Map<String, Integer> resultSetToMap = resultSetToMap(resultSet);
      assertEquals(3, resultSetToMap.size());
      assertEquals(new Integer(2), resultSetToMap.get("abs"));
      assertEquals(new Integer(1), resultSetToMap.get("airbags"));
      assertEquals(new Integer(1), resultSetToMap.get("gps"));

    } finally {
      DBUtils.closeQuietly(resultSet);
      DBUtils.closeQuietly(connection);
    }
  }
  @Test
  public void shouldSetHeaderOnlyMapPropertyAnnotation() throws Exception {
    String xml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<testMethodHeaderOnly>\n" //
            + "    <arg0>foo</arg0>\n" //
            + "</testMethodHeaderOnly>\n";
    when(message.getText()).thenReturn(xml);
    when(message.getPropertyNames()).thenReturn(new StringTokenizer("arg1[A] arg1[B] arg1[C]"));
    when(message.getStringProperty("arg1[A]")).thenReturn("one");
    when(message.getStringProperty("arg1[B]")).thenReturn("two");
    when(message.getStringProperty("arg1[C]")).thenReturn("three");

    XmlMessageDecoder<TestInterfaceHeaderOnlyMap> decoder =
        XmlMessageDecoder.of(TestInterfaceHeaderOnlyMap.class, implMap);

    decoder.onMessage(message);

    Map<String, String> map = new HashMap<String, String>();
    map.put("A", "one");
    map.put("B", "two");
    map.put("C", "three");
    verify(implMap).testMethodHeaderOnly("foo", map);
  }
 public void putUserInCache(UserDetails user) {
   cache.put(user.getUsername(), user);
 }
 public UserDetails getUserFromCache(String username) {
   return (UserDetails) cache.get(username);
 }