Skip to content

Commit

Permalink
1.0 release ready, added a couple of unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryn101 committed Dec 14, 2013
1 parent 719f15b commit e266610
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ gradle
src/main/java/Test.java
src/src.iml
build
lol4j.iml
lol4j.iml
junit.properties
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'java'

sourceCompatibility = 1.5
sourceCompatibility = 1.7
version = '1.0'

repositories {
Expand All @@ -12,6 +12,7 @@ dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.3.0'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.3.0'
compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.4.1'
testCompile group: 'junit', name: 'junit', version: '4.+'
}

jar {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lol4j/exception/InvalidRegionException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/
public class InvalidRegionException extends RuntimeException {
public InvalidRegionException(Region region) {
super("\"" + region.getName() + "\" is not a valid region");
super("\"" + (region == null ? "null" : region.getName()) + "\" is not a valid region");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class AbstractResourceImpl {
private String baseUri;

public void doSupportedRegionCheck(Region region) {
if (!supportedRegions.contains(region)) {
if (region == null || !supportedRegions.contains(region)) {
throw new InvalidRegionException(region);
}
}
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/AbstractResourceImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import lol4j.client.Lol4JClient;
import lol4j.client.impl.Lol4JClientImpl;
import lol4j.util.Region;
import org.junit.BeforeClass;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

/**
* Created by Aaryn101 on 12/14/13.
*/
public abstract class AbstractResourceImplTest {
private static String apiKey = null;
private static String summonerName = null;
private static Long summonerId = null;
private static Region region = null;
private static Lol4JClient client = null;

@BeforeClass
public static void init() {
Properties p = new Properties();
try {
p.load(new FileReader(new File("junit.properties")));
apiKey = p.getProperty("api.key");
summonerName = p.getProperty("summoner.name");
summonerId = Long.parseLong(p.getProperty("summoner.id"));
region = Region.valueOf(p.getProperty("region").toUpperCase());
client = new Lol4JClientImpl(apiKey);
} catch (IOException e) {
e.printStackTrace();
}
}

public static Lol4JClient getClient() {
return client;
}

public static String getApiKey() {
return apiKey;
}

public static String getSummonerName() {
return summonerName;
}

public static Long getSummonerId() {
return summonerId;
}

public static Region getRegion() {
return region;
}
}
55 changes: 55 additions & 0 deletions src/test/java/ChampionResourceImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import lol4j.exception.InvalidRegionException;
import lol4j.protocol.dto.champion.ChampionDto;
import lol4j.protocol.dto.champion.ChampionListDto;
import lol4j.util.Region;
import org.junit.Assert;

/**
* Created by Aaryn101 on 12/13/13.
*/
public class ChampionResourceImplTest extends AbstractResourceImplTest {
@org.junit.Test
public void test_getAllChampions() {
ChampionListDto championList = getClient().getAllChampions(Region.NA, false);

Assert.assertNotNull(championList);
Assert.assertNotNull(championList.getChampions());
Assert.assertNotEquals(championList.getChampions().size(), 0);

ChampionDto champion = championList.getChampions().get(0);
Assert.assertNotNull(champion.getAttackRank());
Assert.assertNotNull(champion.getDefenseRank());
Assert.assertNotNull(champion.getDifficultyRank());
Assert.assertNotNull(champion.getId());
Assert.assertNotNull(champion.getMagicRank());
Assert.assertNotNull(champion.getName());
}

@org.junit.Test
public void test_getAllChampionsWithUnsupportedRegion() {
boolean exceptionThrown = false;

try {
getClient().getAllChampions(Region.TR, false);
}
catch(InvalidRegionException e) {
exceptionThrown = true;
}

Assert.assertTrue(exceptionThrown);
}

@org.junit.Test
public void test_getAllChampionsWithNullRegion() {
boolean exceptionThrown = false;

try {
getClient().getAllChampions(null, false);
}
catch(InvalidRegionException e) {
exceptionThrown = true;
}

Assert.assertTrue(exceptionThrown);
}
}
59 changes: 59 additions & 0 deletions src/test/java/GameResourceImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import lol4j.exception.InvalidRegionException;
import lol4j.protocol.dto.game.GameDto;
import lol4j.protocol.dto.game.RecentGamesDto;
import lol4j.util.Region;
import org.junit.Assert;

/**
* Created by Aaryn101 on 12/14/13.
*/
public class GameResourceImplTest extends AbstractResourceImplTest {
@org.junit.Test
public void test_getRecentGames() {
RecentGamesDto recentGames = getClient().getRecentGames(getRegion(), getSummonerId());

Assert.assertNotNull(recentGames);
Assert.assertNotNull(recentGames.getGames());

if (recentGames.getGames().size() > 0) {
GameDto game = recentGames.getGames().get(0);

Assert.assertNotNull(game.getCreateDateStr());
Assert.assertNotNull(game.getGameMode());
Assert.assertNotNull(game.getGameType());
Assert.assertNotNull(game.getStatistics());
Assert.assertNotEquals(game.getStatistics().size(), 0);
Assert.assertNotNull(game.getSubType());
Assert.assertNotNull(game.getFellowPlayers());
Assert.assertNotEquals(game.getFellowPlayers().size(), 0);
}
}

@org.junit.Test
public void test_getRecentGamesWithUnsupportedRegion() {
boolean exceptionThrown = false;

try {
getClient().getRecentGames(Region.TR, 0L);
}
catch(InvalidRegionException e) {
exceptionThrown = true;
}

Assert.assertTrue(exceptionThrown);
}

@org.junit.Test
public void test_getRecentGamesWithNullRegion() {
boolean exceptionThrown = false;

try {
getClient().getRecentGames(null, 0L);
}
catch(InvalidRegionException e) {
exceptionThrown = true;
}

Assert.assertTrue(exceptionThrown);
}
}

0 comments on commit e266610

Please sign in to comment.