@Test public void removeAllPointsFile(){ Achievement p = new Point(200, "moedas"); gameFile.addAchievement(user, p); assertEquals(p.getName(), gameFile.getAchievement(user, p.getName()).getName()); assertEquals(200, ((Point)gameFile.getAchievement(user, p.getName())).getQuantity().intValue()); gameFile.removeAchievement(user, p); assertNull(gameFile.getAchievement(user, p.getName())); }
@Override public Achievement getAchievement(Object user, String achievName) { Properties prop; Achievement a = null; try { prop = new Properties(); FileInputStream inputFile = new FileInputStream(dir); prop.load(inputFile); for (String key : prop.stringPropertyNames()) { String userName = key.substring(0, key.indexOf(delim)); String achievementType = key.substring(key.indexOf(delim) + 1, key.lastIndexOf(delim)); String achievementName = key.substring(key.lastIndexOf(delim) + 1); String achievementValue = prop.getProperty(key); if (user.toString().equals(userName) && achievementName.equals(achievName)) { a = AchievementFactory.createAchievement(achievementType, achievementName, achievementValue); } } FileOutputStream file = new FileOutputStream(dir); prop.store(file, null); file.close(); } catch (IOException e) { e.printStackTrace(); } return a; }
GameFileStorage extends Game { @Override public Achievement getAchievement(Object user, String achievName) { Properties prop; Achievement a = null; try { prop = new Properties(); FileInputStream inputFile = new FileInputStream(dir); prop.load(inputFile); for (String key : prop.stringPropertyNames()) { String userName = key.substring(0, key.indexOf(delim)); String achievementType = key.substring(key.indexOf(delim) + 1, key.lastIndexOf(delim)); String achievementName = key.substring(key.lastIndexOf(delim) + 1); String achievementValue = prop.getProperty(key); if (user.toString().equals(userName) && achievementName.equals(achievName)) { a = AchievementFactory.createAchievement(achievementType, achievementName, achievementValue); } } FileOutputStream file = new FileOutputStream(dir); prop.store(file, null); file.close(); } catch (IOException e) { e.printStackTrace(); } return a; } }
GameFileStorage extends Game { @Override public Achievement getAchievement(Object user, String achievName) { Properties prop; Achievement a = null; try { prop = new Properties(); FileInputStream inputFile = new FileInputStream(dir); prop.load(inputFile); for (String key : prop.stringPropertyNames()) { String userName = key.substring(0, key.indexOf(delim)); String achievementType = key.substring(key.indexOf(delim) + 1, key.lastIndexOf(delim)); String achievementName = key.substring(key.lastIndexOf(delim) + 1); String achievementValue = prop.getProperty(key); if (user.toString().equals(userName) && achievementName.equals(achievName)) { a = AchievementFactory.createAchievement(achievementType, achievementName, achievementValue); } } FileOutputStream file = new FileOutputStream(dir); prop.store(file, null); file.close(); } catch (IOException e) { e.printStackTrace(); } return a; } GameFileStorage(String fileName); }
GameFileStorage extends Game { @Override public Achievement getAchievement(Object user, String achievName) { Properties prop; Achievement a = null; try { prop = new Properties(); FileInputStream inputFile = new FileInputStream(dir); prop.load(inputFile); for (String key : prop.stringPropertyNames()) { String userName = key.substring(0, key.indexOf(delim)); String achievementType = key.substring(key.indexOf(delim) + 1, key.lastIndexOf(delim)); String achievementName = key.substring(key.lastIndexOf(delim) + 1); String achievementValue = prop.getProperty(key); if (user.toString().equals(userName) && achievementName.equals(achievName)) { a = AchievementFactory.createAchievement(achievementType, achievementName, achievementValue); } } FileOutputStream file = new FileOutputStream(dir); prop.store(file, null); file.close(); } catch (IOException e) { e.printStackTrace(); } return a; } GameFileStorage(String fileName); @Override void insertAchievement(Object user, Achievement a); @Override void deleteAchievement(Object user, Achievement a); @Override Achievement getAchievement(Object user, String achievName); @Override Map<String, Achievement> getAchievements(Object user); @Override void updateAchievement(Object user, Achievement a); @Override Map<String, Achievement> getAllAchievements(Class<? extends Achievement> type); }
GameFileStorage extends Game { @Override public Achievement getAchievement(Object user, String achievName) { Properties prop; Achievement a = null; try { prop = new Properties(); FileInputStream inputFile = new FileInputStream(dir); prop.load(inputFile); for (String key : prop.stringPropertyNames()) { String userName = key.substring(0, key.indexOf(delim)); String achievementType = key.substring(key.indexOf(delim) + 1, key.lastIndexOf(delim)); String achievementName = key.substring(key.lastIndexOf(delim) + 1); String achievementValue = prop.getProperty(key); if (user.toString().equals(userName) && achievementName.equals(achievName)) { a = AchievementFactory.createAchievement(achievementType, achievementName, achievementValue); } } FileOutputStream file = new FileOutputStream(dir); prop.store(file, null); file.close(); } catch (IOException e) { e.printStackTrace(); } return a; } GameFileStorage(String fileName); @Override void insertAchievement(Object user, Achievement a); @Override void deleteAchievement(Object user, Achievement a); @Override Achievement getAchievement(Object user, String achievName); @Override Map<String, Achievement> getAchievements(Object user); @Override void updateAchievement(Object user, Achievement a); @Override Map<String, Achievement> getAllAchievements(Class<? extends Achievement> type);  }