[LIB-2] Add snooker-score-api source files
[snooker-score-api.git] / src / test / java / org / hedgecode / snooker / json / JsonRankingsTest.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.Ranking;
20
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.JUnit4;
24
25 /**
26  * Tests for {@link JsonRankings}.
27  *
28  * @author Dmitry Samoshin aka gotty
29  */
30 @RunWith(JUnit4.class)
31 public class JsonRankingsTest extends AbstractJsonTest {
32
33     @Test
34     public void testRankings() throws Exception {
35         JsonRankings actualRankings = new JsonRankings(
36                 GSON.fromJson(
37                         JsonStringToken.token(
38                                 jsonFromFile()
39                         ),
40                         JsonRanking[].class
41                 )
42         );
43         //serialize(actualRankings);
44         JsonRankings expectedRankings = (JsonRankings) deserialize();
45         assertEquals(
46                 expectedRankings,
47                 actualRankings
48         );
49     }
50
51     public static void assertEquals(JsonRankings expecteds, JsonRankings actuals) {
52         assertEquals(
53                 expecteds.size(),
54                 actuals.size()
55         );
56         for (Ranking expected : expecteds) {
57             JsonRankingTest.assertEquals(
58                     (JsonRanking) expected,
59                     (JsonRanking) actuals.byId(expected.getId())
60             );
61         }
62     }
63
64 }