[LIB-2] Add snooker-score-api source files
[snooker-score-api.git] / src / test / java / org / hedgecode / snooker / json / JsonPlayersTest.java
1 /*
2  * Copyright (c) 2017. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.snooker.json;
18
19 import org.hedgecode.snooker.api.Player;
20
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.JUnit4;
24
25 /**
26  * Tests for {@link JsonPlayers}.
27  *
28  * @author Dmitry Samoshin aka gotty
29  */
30 @RunWith(JUnit4.class)
31 public class JsonPlayersTest extends AbstractJsonTest {
32
33     @Test
34     public void testPlayers() throws Exception {
35         JsonPlayers actualPlayers = new JsonPlayers(
36                 GSON.fromJson(
37                         JsonStringToken.token(
38                                 jsonFromFile()
39                         ),
40                         JsonPlayer[].class
41                 )
42         );
43         //serialize(actualPlayers);
44         JsonPlayers expectedPlayers = (JsonPlayers) deserialize();
45         assertEquals(
46                 expectedPlayers,
47                 actualPlayers
48         );
49     }
50
51     public static void assertEquals(JsonPlayers expecteds, JsonPlayers actuals) {
52         assertEquals(
53                 expecteds.size(),
54                 actuals.size()
55         );
56         for (Player expected : expecteds) {
57             JsonPlayerTest.assertEquals(
58                     (JsonPlayer) expected,
59                     (JsonPlayer) actuals.byId(expected.getId())
60             );
61         }
62     }
63
64 }