Fixup variable names

This commit is contained in:
andrebrowne 2020-04-25 07:42:28 -04:00
parent 925a69b401
commit 4426454a9a
1 changed files with 106 additions and 106 deletions

View File

@ -38,134 +38,134 @@ public class HibernateTypesIntegrationTest {
@Test @Test
void hibernateTypeJsonTest() { void whenSavingHibernateTypes_thenTheCorrectJsonIsStoredInTheDatabase() {
Album nullAlbum = new Album(); Album emptyAlbum = new Album();
nullAlbum = albumRepository.save(nullAlbum); emptyAlbum = albumRepository.save(emptyAlbum);
Song nullSong = new Song(); Song emptySong = new Song();
nullSong = songRepository.save(nullSong); emptySong = songRepository.save(emptySong);
Artist artist0 = new Artist(); Artist superstarArtist = new Artist();
artist0.setCountry("England"); superstarArtist.setCountry("England");
artist0.setGenre("Pop"); superstarArtist.setGenre("Pop");
artist0.setName("Superstar"); superstarArtist.setName("Superstar");
Song song0 = new Song(); Song aHappySong = new Song();
song0.setArtist(artist0); aHappySong.setArtist(superstarArtist);
song0.setName("A Happy Song"); aHappySong.setName("A Happy Song");
song0.setLength(Duration.ofMinutes(4).getSeconds()); aHappySong.setLength(Duration.ofMinutes(4).getSeconds());
song0 = songRepository.save(song0); aHappySong = songRepository.save(aHappySong);
Song song1 = new Song(); Song aSadSong = new Song();
song1.setArtist(artist0); aSadSong.setArtist(superstarArtist);
song1.setName("A Sad Song"); aSadSong.setName("A Sad Song");
song1.setLength(Duration.ofMinutes(2).getSeconds()); aSadSong.setLength(Duration.ofMinutes(2).getSeconds());
song1 = songRepository.save(song1); aSadSong = songRepository.save(aSadSong);
Song song2 = new Song(); Song anotherHappySong = new Song();
song2.setArtist(artist0); anotherHappySong.setArtist(superstarArtist);
song2.setName("Another Happy Song"); anotherHappySong.setName("Another Happy Song");
song2.setLength(Duration.ofMinutes(3).getSeconds()); anotherHappySong.setLength(Duration.ofMinutes(3).getSeconds());
song2 = songRepository.save(song2); anotherHappySong = songRepository.save(anotherHappySong);
Artist artist1 = new Artist(); Artist newcomer = new Artist();
artist1.setCountry("Jamaica"); newcomer.setCountry("Jamaica");
artist1.setGenre("Reggae"); newcomer.setGenre("Reggae");
artist1.setName("Newcomer"); newcomer.setName("Newcomer");
Song song3 = new Song(); Song aNewSong = new Song();
song3.setArtist(artist1); aNewSong.setArtist(newcomer);
song3.setName("A New Song"); aNewSong.setName("A New Song");
song3.setLength(Duration.ofMinutes(5).getSeconds()); aNewSong.setLength(Duration.ofMinutes(5).getSeconds());
song3 = songRepository.save(song3); aNewSong = songRepository.save(aNewSong);
CoverArt album0CoverArt = new CoverArt(); CoverArt superstarAlbumCoverArt = new CoverArt();
album0CoverArt.setUpcCode(UUID.randomUUID().toString()); superstarAlbumCoverArt.setUpcCode(UUID.randomUUID().toString());
album0CoverArt.setFrontCoverArtUrl("http://fakeurl-0"); superstarAlbumCoverArt.setFrontCoverArtUrl("http://fakeurl-0");
album0CoverArt.setBackCoverArtUrl("http://fakeurl-1"); superstarAlbumCoverArt.setBackCoverArtUrl("http://fakeurl-1");
Album album0 = new Album(); Album superstarAlbum = new Album();
album0.setCoverArt(album0CoverArt); superstarAlbum.setCoverArt(superstarAlbumCoverArt);
album0.setName("Album 0"); superstarAlbum.setName("The Superstar Album");
album0.setSong(Lists.newArrayList(song0, song1, song2)); superstarAlbum.setSong(Lists.newArrayList(aHappySong, aSadSong, anotherHappySong));
album0 = albumRepository.save(album0); superstarAlbum = albumRepository.save(superstarAlbum);
CoverArt album1CoverArt = new CoverArt(); CoverArt newcomerAlbumCoverArt = new CoverArt();
album1CoverArt.setUpcCode(UUID.randomUUID().toString()); newcomerAlbumCoverArt.setUpcCode(UUID.randomUUID().toString());
album1CoverArt.setFrontCoverArtUrl("http://fakeurl-2"); newcomerAlbumCoverArt.setFrontCoverArtUrl("http://fakeurl-2");
album1CoverArt.setBackCoverArtUrl("http://fakeurl-3"); newcomerAlbumCoverArt.setBackCoverArtUrl("http://fakeurl-3");
Album album1 = new Album(); Album newcomerAlbum = new Album();
album1.setCoverArt(album1CoverArt); newcomerAlbum.setCoverArt(newcomerAlbumCoverArt);
album1.setName("Album 1"); newcomerAlbum.setName("The Newcomer Album");
album1.setSong(Lists.newArrayList(song3)); newcomerAlbum.setSong(Lists.newArrayList(aNewSong));
albumRepository.save(album1); albumRepository.save(newcomerAlbum);
Iterable<Album> queryAlbumsResult = albumRepository.findAll(); Iterable<Album> selectAlbumsQueryResult = albumRepository.findAll();
assertThat(queryAlbumsResult).hasSize(3); assertThat(selectAlbumsQueryResult).hasSize(3);
Iterable<Song> querySongsResult = songRepository.findAll(); Iterable<Song> selectSongsQueryResult = songRepository.findAll();
assertThat(querySongsResult).hasSize(5); assertThat(selectSongsQueryResult).hasSize(5);
Album queryAlbumResult; Album selectAlbumQueryResult;
queryAlbumResult = albumRepository.findById(nullAlbum.getId()).get(); selectAlbumQueryResult = albumRepository.findById(emptyAlbum.getId()).get();
assertThat(queryAlbumResult.getName()).isNull(); assertThat(selectAlbumQueryResult.getName()).isNull();
assertThat(queryAlbumResult.getCoverArt()).isNull(); assertThat(selectAlbumQueryResult.getCoverArt()).isNull();
assertThat(queryAlbumResult.getSongs()).isNullOrEmpty(); assertThat(selectAlbumQueryResult.getSongs()).isNullOrEmpty();
queryAlbumResult = albumRepository.findById(album0.getId()).get(); selectAlbumQueryResult = albumRepository.findById(superstarAlbum.getId()).get();
assertThat(queryAlbumResult.getName()).isEqualTo("Album 0"); assertThat(selectAlbumQueryResult.getName()).isEqualTo("Album 0");
assertThat(queryAlbumResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-0"); assertThat(selectAlbumQueryResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-0");
assertThat(queryAlbumResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-1"); assertThat(selectAlbumQueryResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-1");
assertThat(queryAlbumResult.getSongs()).hasSize(3); assertThat(selectAlbumQueryResult.getSongs()).hasSize(3);
assertThat(queryAlbumResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(song0, song1, song2); assertThat(selectAlbumQueryResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(aHappySong, aSadSong, anotherHappySong);
queryAlbumResult = albumRepository.findById(album1.getId()).get(); selectAlbumQueryResult = albumRepository.findById(superstarAlbum.getId()).get();
assertThat(queryAlbumResult.getName()).isEqualTo("Album 1"); assertThat(selectAlbumQueryResult.getName()).isEqualTo("Album 1");
assertThat(queryAlbumResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-2"); assertThat(selectAlbumQueryResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-2");
assertThat(queryAlbumResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-3"); assertThat(selectAlbumQueryResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-3");
assertThat(queryAlbumResult.getSongs()).hasSize(1); assertThat(selectAlbumQueryResult.getSongs()).hasSize(1);
assertThat(queryAlbumResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(song3); assertThat(selectAlbumQueryResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(aNewSong);
Song querySongResult; Song selectSongQueryResult;
querySongResult = songRepository.findById(nullSong.getId()).get(); selectSongQueryResult = songRepository.findById(emptySong.getId()).get();
assertThat(querySongResult.getName()).isNull(); assertThat(selectSongQueryResult.getName()).isNull();
assertThat(querySongResult.getLength()).isZero(); assertThat(selectSongQueryResult.getLength()).isZero();
assertThat(querySongResult.getArtist()).isNull(); assertThat(selectSongQueryResult.getArtist()).isNull();
querySongResult = songRepository.findById(song0.getId()).get(); selectSongQueryResult = songRepository.findById(aHappySong.getId()).get();
assertThat(querySongResult.getName()).isEqualTo("A Happy Song"); assertThat(selectSongQueryResult.getName()).isEqualTo("A Happy Song");
assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(4).getSeconds()); assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(4).getSeconds());
assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Superstar");
assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Pop");
assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("England");
querySongResult = songRepository.findById(song1.getId()).get(); selectSongQueryResult = songRepository.findById(aSadSong.getId()).get();
assertThat(querySongResult.getName()).isEqualTo("A Sad Song"); assertThat(selectSongQueryResult.getName()).isEqualTo("A Sad Song");
assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(2).getSeconds()); assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(2).getSeconds());
assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Superstar");
assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Pop");
assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("England");
querySongResult = songRepository.findById(song2.getId()).get(); selectSongQueryResult = songRepository.findById(anotherHappySong.getId()).get();
assertThat(querySongResult.getName()).isEqualTo("Another Happy Song"); assertThat(selectSongQueryResult.getName()).isEqualTo("Another Happy Song");
assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(3).getSeconds()); assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(3).getSeconds());
assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Superstar");
assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Pop");
assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("England");
querySongResult = songRepository.findById(song3.getId()).get(); selectSongQueryResult = songRepository.findById(aNewSong.getId()).get();
assertThat(querySongResult.getName()).isEqualTo("A New Song"); assertThat(selectSongQueryResult.getName()).isEqualTo("A New Song");
assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(5).getSeconds()); assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(5).getSeconds());
assertThat(querySongResult.getArtist().getName()).isEqualTo("Newcomer"); assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Newcomer");
assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Reggae"); assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Reggae");
assertThat(querySongResult.getArtist().getCountry()).isEqualTo("Jamaica"); assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("Jamaica");
} }
@Test @Test
void hibernateTypeYearMonthTest() { void whenSavingAHibernateTypeYearMonth_thenTheCorrectValueIsStoredInTheDatabase() {
Song mySong = new Song(); Song mySong = new Song();
YearMonth now = YearMonth.of(2019, 12); YearMonth now = YearMonth.of(2019, 12);
mySong.setArtist(new Artist()); mySong.setArtist(new Artist());
@ -174,9 +174,9 @@ public class HibernateTypesIntegrationTest {
mySong.setRecordedOn(now); mySong.setRecordedOn(now);
mySong = songRepository.save(mySong); mySong = songRepository.save(mySong);
Song queryResult; Song selectSongQueryResult;
queryResult = songRepository.findById(mySong.getId()).get(); selectSongQueryResult = songRepository.findById(mySong.getId()).get();
assertThat(queryResult.getRecordedOn().getYear()).isEqualTo(2019); assertThat(selectSongQueryResult.getRecordedOn().getYear()).isEqualTo(2019);
assertThat(queryResult.getRecordedOn().getMonthValue()).isEqualTo(12); assertThat(selectSongQueryResult.getRecordedOn().getMonthValue()).isEqualTo(12);
} }
} }