Dictionary implements Parcelable { public Translation getTranslationBySourcePhrase(String sourcePhrase) { for (Translation translation : translations) { if (sourcePhrase.equals(translation.getLabel())) { return translation; } } return new Translation(); } Dictionary(String language, Translation[] translations, long dbId);  Dictionary(String language); protected  Dictionary(Parcel in); String getLanguage(); int getTranslationCount(); Translation getTranslation(int index); Translation getTranslationBySourcePhrase(String sourcePhrase); long getDbId(); @Override String toString(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Creator<Dictionary> CREATOR; }
@Test public void shouldCreateANewTranslationWhenATranslationCannotBeFoundBySourcePhrase() { Dictionary dictionary = new Dictionary(""); Translation translation = dictionary.getTranslationBySourcePhrase("Some Phrase"); assertEquals(translation, new Translation()); }
@Test public void shouldFindATranslationBySourcePhrase() { Translation firstTranslation = mock(Translation.class); when(firstTranslation.getLabel()).thenReturn("A Label"); Translation secondTranslation = mock(Translation.class); Dictionary dictionary = new Dictionary("", new Translation[]{firstTranslation, secondTranslation}, 1L); Translation translation = dictionary.getTranslationBySourcePhrase("A Label"); assertEquals(translation, firstTranslation); }