@Test public void testSetupData() { // Retrieve the sample data from our database and make sure it's what we // expect Player playerWith0Friends = TestUtils.getPlayer(1000); Player playerWith1Friends = TestUtils.getPlayer(1001); Player playerWith4Friends = TestUtils.getPlayer(1004); Player playerWith5Friends = TestUtils.getPlayer(1005); Player playerWith10Friends = TestUtils.getPlayer(1010); Assert.assertTrue(playerWith0Friends.getFriendList().size() == 0); Assert.assertTrue(playerWith1Friends.getFriendList().size() == 1); Assert.assertTrue(playerWith4Friends.getFriendList().size() == 4); Assert.assertTrue(playerWith5Friends.getFriendList().size() == 5); Assert.assertTrue(playerWith10Friends.getFriendList().size() == 10); Assert.assertTrue(playerWith10Friends.getFriendList().get(0) == 67890); User twoFriend = TestUtils.getUser(playerWith5Friends.getFriendList().get(1)); Assert.assertTrue(twoFriend.getName().equals("Two Friend")); }
private boolean isValidGameLinkLists(String HrefBeginning, Player player) { // Parse the player's GameLink to get the friendIDList and // friendNameList int friendIDStart = HrefBeginning.length(); int friendIDEnd = player.getGameLink().getHref().indexOf("&friendNameList="); String friendIDs = player.getGameLink().getHref().substring(friendIDStart, friendIDEnd); int friendNameStart = player.getGameLink().getHref().indexOf("friendNameList=") + 15; // we need to add // len("friendNameList=") String friendNames = player.getGameLink().getHref().substring(friendNameStart); ArrayList<String> friendIDList = getListFromString(friendIDs); ArrayList<String> friendNamesList = getListFromString(friendNames); for (String friendID : friendIDList) { // Check that each friendID matches to a name in the friendNameList User curUser = TestUtils.getUser(Long.valueOf(friendID)); if (curUser == null) { System.out.println("No User found in DB for ID: " + friendID); return false; } else { if (userNameInList(curUser, friendNamesList) == false) { System.out.println( curUser.getName() + ", ID [" + friendID + "was not in the friendNamesList"); return false; } } // Ensure each friendID is a member of the player's friendList if (player.getFriendList().contains(Long.valueOf(friendID)) == false) { System.out.println( "ID [" + friendID + "] is not among the players friendlist" + player.getFriendList()); return false; } } return true; }