From: gotty Date: Wed, 18 Sep 2019 23:16:14 +0000 (+0000) Subject: [LIB-8] Add Tests for Event Rounds and Seedings functional X-Git-Url: https://git.hedgecode.org/?a=commitdiff_plain;h=0de1829b9828b5916142579b85667b84bf8862ba;p=snooker-score-api.git [LIB-8] Add Tests for Event Rounds and Seedings functional git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@172 fb0bcced-7025-49ed-a12f-f98bce993226 --- diff --git a/src/test/java/org/hedgecode/snooker/json/JsonRoundTest.java b/src/test/java/org/hedgecode/snooker/json/JsonRoundTest.java new file mode 100644 index 0000000..912e336 --- /dev/null +++ b/src/test/java/org/hedgecode/snooker/json/JsonRoundTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017-2019. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.snooker.json; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link JsonRound}. + * + * @author Dmitry Samoshin aka gotty + */ +@RunWith(JUnit4.class) +public class JsonRoundTest extends AbstractJsonTest { + + @Test + public void testRound() throws Exception { + JsonRound[] jsonRounds = GSON.fromJson( + JsonStringToken.token( + jsonFromFile() + ), + JsonRound[].class + ); + //serialize(jsonRounds[0]); + JsonRound expectedRound = (JsonRound) deserialize(); + assertNull( + expectedRound, + jsonRounds + ); + JsonRound actualRound = jsonRounds[0]; + assertEquals( + expectedRound, + actualRound + ); + } + + public static void assertEquals(JsonRound expected, JsonRound actual) { + assertEquals(expected.round(), actual.round()); + assertEquals(expected.roundName(), actual.roundName()); + assertEquals(expected.eventId(), actual.eventId()); + assertEquals(expected.mainEventId(), actual.mainEventId()); + assertEquals(expected.distance(), actual.distance()); + assertEquals(expected.numLeft(), actual.numLeft()); + assertEquals(expected.numMatches(), actual.numMatches()); + assertEquals(expected.note(), actual.note()); + assertEquals(expected.valueType(), actual.valueType()); + assertEquals(expected.rank(), actual.rank()); + assertEquals(expected.money(), actual.money()); + assertEquals(expected.seedGetsHalf(), actual.seedGetsHalf()); + assertEquals(expected.actualMoney(), actual.actualMoney()); + assertEquals(expected.currency(), actual.currency()); + assertEquals(expected.conversionRate(), actual.conversionRate()); + assertEquals(expected.points(), actual.points()); + assertEquals(expected.seedPoints(), actual.seedPoints()); + } + +} \ No newline at end of file diff --git a/src/test/java/org/hedgecode/snooker/json/JsonRoundsTest.java b/src/test/java/org/hedgecode/snooker/json/JsonRoundsTest.java new file mode 100644 index 0000000..f1e1d3d --- /dev/null +++ b/src/test/java/org/hedgecode/snooker/json/JsonRoundsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017-2019. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.snooker.json; + +import org.hedgecode.snooker.api.Round; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link JsonRounds}. + * + * @author Dmitry Samoshin aka gotty + */ +@RunWith(JUnit4.class) +public class JsonRoundsTest extends AbstractJsonTest { + + @Test + public void testRounds() throws Exception { + JsonRounds actualRounds = new JsonRounds( + GSON.fromJson( + JsonStringToken.token( + jsonFromFile() + ), + JsonRound[].class + ) + ); + //serialize(actualRounds); + JsonRounds expectedRounds = (JsonRounds) deserialize(); + assertEquals( + expectedRounds, + actualRounds + ); + } + + public static void assertEquals(JsonRounds expecteds, JsonRounds actuals) { + assertEquals( + expecteds.size(), + actuals.size() + ); + for (Round expected : expecteds) { + JsonRoundTest.assertEquals( + (JsonRound) expected, + (JsonRound) actuals.byId(expected.getId()) + ); + } + } + +} \ No newline at end of file diff --git a/src/test/java/org/hedgecode/snooker/json/JsonSeedingTest.java b/src/test/java/org/hedgecode/snooker/json/JsonSeedingTest.java new file mode 100644 index 0000000..d65fc18 --- /dev/null +++ b/src/test/java/org/hedgecode/snooker/json/JsonSeedingTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017-2019. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.snooker.json; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link JsonSeeding}. + * + * @author Dmitry Samoshin aka gotty + */ +@RunWith(JUnit4.class) +public class JsonSeedingTest extends AbstractJsonTest { + + @Test + public void testSeeding() throws Exception { + JsonSeeding[] jsonSeedings = GSON.fromJson( + JsonStringToken.token( + jsonFromFile() + ), + JsonSeeding[].class + ); + //serialize(jsonSeedings[0]); + JsonSeeding expectedSeeding = (JsonSeeding) deserialize(); + assertNull( + expectedSeeding, + jsonSeedings + ); + JsonSeeding actualSeeding = jsonSeedings[0]; + assertEquals( + expectedSeeding, + actualSeeding + ); + } + + public static void assertEquals(JsonSeeding expected, JsonSeeding actual) { + assertEquals(expected.eventId(), actual.eventId()); + assertEquals(expected.playerId(), actual.playerId()); + assertEquals(expected.seeding(), actual.seeding()); + } + +} \ No newline at end of file diff --git a/src/test/java/org/hedgecode/snooker/json/JsonSeedingsTest.java b/src/test/java/org/hedgecode/snooker/json/JsonSeedingsTest.java new file mode 100644 index 0000000..c670a86 --- /dev/null +++ b/src/test/java/org/hedgecode/snooker/json/JsonSeedingsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017-2019. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.snooker.json; + +import org.hedgecode.snooker.api.Seeding; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link JsonSeedings}. + * + * @author Dmitry Samoshin aka gotty + */ +@RunWith(JUnit4.class) +public class JsonSeedingsTest extends AbstractJsonTest { + + @Test + public void testSeedings() throws Exception { + JsonSeedings actualSeedings = new JsonSeedings( + GSON.fromJson( + JsonStringToken.token( + jsonFromFile() + ), + JsonSeeding[].class + ) + ); + //serialize(actualSeedings); + JsonSeedings expectedSeedings = (JsonSeedings) deserialize(); + assertEquals( + expectedSeedings, + actualSeedings + ); + } + + public static void assertEquals(JsonSeedings expecteds, JsonSeedings actuals) { + assertEquals( + expecteds.size(), + actuals.size() + ); + for (Seeding expected : expecteds) { + JsonSeedingTest.assertEquals( + (JsonSeeding) expected, + (JsonSeeding) actuals.byId(expected.getId()) + ); + } + } + +} \ No newline at end of file