// Path: app/src/main/java/com/mypodcasts/repositories/models/Episode.java
// public class Episode implements Serializable {
// 
//   private String title;
//   private String publishedDate;
//   private String description;
//   private String duration;
//   private Audio audio;
//   private Feed podcast;
//   private Image image;
// 
//   public Image getImage() {
//     return image;
//   }
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Date getPublishedDate() {
//     if (publishedDate == null) { return null; }
// 
//     return dateTimeParser().parseDateTime(publishedDate).toDate();
//   }
// 
//   public String getDescription() {
//     return description == null ? "" : description;
//   }
// 
//   public String getDuration() {
//     return duration;
//   }
// 
//   public Feed getFeed() {
//     if (podcast == null) { return new Feed(); }
// 
//     return podcast;
//   }
// 
//   public String getAudioFilePath() {
//     return getFeed().getId() + "/" + getTitle() + ".mp3";
//   }
// 
//   public String getAudioUrl() {
//     return getAudio().getUrl();
//   }
// 
//   public String getAudioLength() {
//     return getAudio().getLength();
//   }
// 
//   protected Audio getAudio() {
//     if (audio == null) { return new EmptyAudio(); }
// 
//     return audio;
//   }
// 
//   @Override
//   public String toString() {
//     return format(
//         "{ \"title\": %s, " +
//             "\"audioFilePath\": %s, " +
//             "\"feed\": { \"id\": %s, \"title\": %s } " +
//         "}",
//         getTitle(),
//         getAudioFilePath(),
//         getFeed().getId(),
//         getFeed().getTitle()
//     );
//   }
// 
//   private class EmptyAudio extends Audio {
//     @Override
//     public String getUrl() {
//       return "";
//     }
// 
//     @Override
//     public String getLength() {
//       return "0";
//     }
//   }
// }
// 
// Path: app/src/main/java/com/mypodcasts/repositories/models/Feed.java
// public class Feed implements Serializable {
//   private String id;
//   private String title;
//   private Image image;
//   private List<Episode> episodes;
// 
//   public String getId() {
//     return id;
//   }
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Image getImage() {
//     return image;
//   }
// 
//   public List<Episode> getEpisodes() {
//     return episodes;
//   }
// 
// }
// 
// Path: app/src/test/java/com/mypodcasts/util/EpisodeHelper.java
// public static Episode anEpisode() {
//   return new Episode() {
//     @Override public String getTitle() {
//       return "An awesome episode";
//     }
// 
//     @Override public Feed getFeed() {
//       return new Feed() {
//         @Override
//         public String getId() {
//           return "crazy_id_123";
//         }
//       };
//     }
//   };
// }


import android.content.SharedPreferences;
import com.mypodcasts.BuildConfig;
import com.mypodcasts.repositories.models.Episode;
import com.mypodcasts.repositories.models.Feed;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Random;
import static android.content.Context.MODE_PRIVATE;
import static com.mypodcasts.util.EpisodeHelper.anEpisode;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.robolectric.RuntimeEnvironment.application;
package com.mypodcasts.episodes;






@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class EpisodeCheckpointTest {

  EpisodeCheckpoint episodeCheckpoint;

  @Before
  public void setup() {
    episodeCheckpoint = new EpisodeCheckpoint(application);
  }

  @Test
  public void itStoresCurrentStateOfPlayingEpisode() {
    int audioPosition = new Random().nextInt();

    assertThat(episodeCheckpoint.markCheckpoint(anEpisode(), audioPosition), is(audioPosition));
    assertThat(
        getSharedPreferences().getInt("podcast_crazy_id_123#episode_an_awesome_episode", 0),
        is(audioPosition)
    );
  }

  @Test
  public void itFetchesCurrentStateOfPlayingEpisode() {
    int audioPosition = new Random().nextInt();

    SharedPreferences.Editor editor = getSharedPreferences().edit();
    editor.putInt("podcast_crazy_id_123#episode_an_awesome_episode", audioPosition).apply();

    assertThat(episodeCheckpoint.getLastCheckpointPosition(anEpisode(), 0), is(audioPosition));
  }

  @Test
  public void itReturnsDefaultValueWhenCouldNotFindEpisodeCheckpointOfPlayingEpisode() {
// Path: app/src/main/java/com/mypodcasts/repositories/models/Episode.java
// public class Episode implements Serializable {
// 
//   private String title;
//   private String publishedDate;
//   private String description;
//   private String duration;
//   private Audio audio;
//   private Feed podcast;
//   private Image image;
// 
//   public Image getImage() {
//     return image;
//   }
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Date getPublishedDate() {
//     if (publishedDate == null) { return null; }
// 
//     return dateTimeParser().parseDateTime(publishedDate).toDate();
//   }
// 
//   public String getDescription() {
//     return description == null ? "" : description;
//   }
// 
//   public String getDuration() {
//     return duration;
//   }
// 
//   public Feed getFeed() {
//     if (podcast == null) { return new Feed(); }
// 
//     return podcast;
//   }
// 
//   public String getAudioFilePath() {
//     return getFeed().getId() + "/" + getTitle() + ".mp3";
//   }
// 
//   public String getAudioUrl() {
//     return getAudio().getUrl();
//   }
// 
//   public String getAudioLength() {
//     return getAudio().getLength();
//   }
// 
//   protected Audio getAudio() {
//     if (audio == null) { return new EmptyAudio(); }
// 
//     return audio;
//   }
// 
//   @Override
//   public String toString() {
//     return format(
//         "{ \"title\": %s, " +
//             "\"audioFilePath\": %s, " +
//             "\"feed\": { \"id\": %s, \"title\": %s } " +
//         "}",
//         getTitle(),
//         getAudioFilePath(),
//         getFeed().getId(),
//         getFeed().getTitle()
//     );
//   }
// 
//   private class EmptyAudio extends Audio {
//     @Override
//     public String getUrl() {
//       return "";
//     }
// 
//     @Override
//     public String getLength() {
//       return "0";
//     }
//   }
// }
// 
// Path: app/src/main/java/com/mypodcasts/repositories/models/Feed.java
// public class Feed implements Serializable {
//   private String id;
//   private String title;
//   private Image image;
//   private List<Episode> episodes;
// 
//   public String getId() {
//     return id;
//   }
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Image getImage() {
//     return image;
//   }
// 
//   public List<Episode> getEpisodes() {
//     return episodes;
//   }
// 
// }
// 
// Path: app/src/test/java/com/mypodcasts/util/EpisodeHelper.java
// public static Episode anEpisode() {
//   return new Episode() {
//     @Override public String getTitle() {
//       return "An awesome episode";
//     }
// 
//     @Override public Feed getFeed() {
//       return new Feed() {
//         @Override
//         public String getId() {
//           return "crazy_id_123";
//         }
//       };
//     }
//   };
// }


// Path: app/src/test/java/com/mypodcasts/episodes/EpisodeCheckpointTest.java
import android.content.SharedPreferences;
import com.mypodcasts.BuildConfig;
import com.mypodcasts.repositories.models.Episode;
import com.mypodcasts.repositories.models.Feed;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Random;
import static android.content.Context.MODE_PRIVATE;
import static com.mypodcasts.util.EpisodeHelper.anEpisode;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.robolectric.RuntimeEnvironment.application;

package com.mypodcasts.episodes;






@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class EpisodeCheckpointTest {

  EpisodeCheckpoint episodeCheckpoint;

  @Before
  public void setup() {
    episodeCheckpoint = new EpisodeCheckpoint(application);
  }

  @Test
  public void itStoresCurrentStateOfPlayingEpisode() {
    int audioPosition = new Random().nextInt();

    assertThat(episodeCheckpoint.markCheckpoint(anEpisode(), audioPosition), is(audioPosition));
    assertThat(
        getSharedPreferences().getInt("podcast_crazy_id_123#episode_an_awesome_episode", 0),
        is(audioPosition)
    );
  }

  @Test
  public void itFetchesCurrentStateOfPlayingEpisode() {
    int audioPosition = new Random().nextInt();

    SharedPreferences.Editor editor = getSharedPreferences().edit();
    editor.putInt("podcast_crazy_id_123#episode_an_awesome_episode", audioPosition).apply();

    assertThat(episodeCheckpoint.getLastCheckpointPosition(anEpisode(), 0), is(audioPosition));
  }

  @Test
  public void itReturnsDefaultValueWhenCouldNotFindEpisodeCheckpointOfPlayingEpisode() {
    assertThat(episodeCheckpoint.getLastCheckpointPosition(anEpisode(), 42), is(42));