@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());
 }
  @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);
  }
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);
    }
  }
 public void putUserInCache(UserDetails user) {
   cache.put(user.getUsername(), user);
 }