/** Method: readFromFile() */ @Test public void testReadFromFile() throws Exception { GameNode testGameNode = new GameNode(); testGameNode.setPlayer("rarry"); testGameNode.setOpponent("lobertie"); testGameNode.setGameName("raddle"); testGameNode.setWinLose(true); testGameNode.setScore(29); LinkedList<GameNode> testLLGN = new LinkedList<GameNode>(); testLLGN.add(testGameNode); try { FileOutputStream fileOut = new FileOutputStream("gameStats.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(testLLGN); out.close(); fileOut.close(); } catch (IOException e) { } testScoreboard.readFromFile(); assertTrue( "Is a public method that returns void and only alters a private variable with no getter. Should be made" + " a private method, should allow for ScoreInfo access or should not be tested", false); }
/** Method: addToFile(LinkedList<GameNode> g) */ @Test public void testAddToFile() throws Exception { GameNode testGameNode = new GameNode(); testGameNode.setPlayer("rarry"); testGameNode.setOpponent("lobertie"); testGameNode.setGameName("raddle"); testGameNode.setWinLose(true); testGameNode.setScore(29); LinkedList<GameNode> testLLGN = new LinkedList<GameNode>(); testLLGN.add(testGameNode); testScoreboard.addToFile(testLLGN); LinkedList<GameNode> temp = new LinkedList<GameNode>(); ObjectInputStream i = null; try { i = new ObjectInputStream(new FileInputStream("gameStats.ser")); temp = (LinkedList<GameNode>) i.readObject(); i.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } catch (ClassNotFoundException e) { e.printStackTrace(); } assertTrue( "The Object read from file contains the testGameNode added to file", temp.contains(testGameNode)); }