Пример #1
0
  @Test
  public void testLoad() {
    // Save the game
    mSavedGameManager.save(mGame);

    // Load the game
    Game game = mSavedGameManager.load();
    assertNotNull(game);
    assertEquals("Loaded game is not the same as what was saved.", game, mGame);
  }
Пример #2
0
  @Test
  public void testSave() {
    Gson gson = new GsonBuilder().create();
    String gameJson = gson.toJson(mGame);

    // Save the game
    mSavedGameManager.save(mGame);

    FileInputStream in = null;
    try {
      in = mActivity.openFileInput(mSavedGameManager.getFilename());
    } catch (FileNotFoundException e) {
      Log.d(TAG, "No game has been previously saved.");
      return;
    }

    try {
      assertEquals("Saved game is not the same.", gameJson, IOUtils.toString(in, "UTF-8"));
    } catch (IOException e) {
      Log.e(TAG, "File could not be read.", e);
      return;
    }
  }