Skip to content

Commit

Permalink
Group service tests with Nested for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
drumonii committed Oct 25, 2019
1 parent 7ce8a0c commit b5cd872
Show file tree
Hide file tree
Showing 6 changed files with 500 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.drumonii.loltrollbuild.model.Version;
import com.drumonii.loltrollbuild.model.image.Image;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.web.util.UriComponentsBuilder;

Expand All @@ -13,75 +15,87 @@ class ImageFetcherTest {

private ImageFetcher imageFetcher = new ImageFetcher();

@Test
void setsImagesSourcesWithInvalidUrl() {
Image image1 = new Image("Aatrox.png", "champion0.png", "champion", new byte[0], 0, 0, 48, 48);
Image image2 = new Image("Akali.png", "champion0.png", "champion", new byte[0], 96, 0, 48, 48);
@Nested
@DisplayName("setImgsSrcs")
class ImgSrcs {

UriComponentsBuilder builder = UriComponentsBuilder
.fromPath("/cdn/{latestVersion}/img/champion/{champion}");
@Test
void withInvalidUrl() {
Image image1 = new Image("Aatrox.png", "champion0.png", "champion", new byte[0], 0, 0, 48, 48);
Image image2 = new Image("Akali.png", "champion0.png", "champion", new byte[0], 96, 0, 48, 48);

Version latestVersion = Version.patch("6.24.1");
UriComponentsBuilder builder = UriComponentsBuilder
.fromPath("/cdn/{latestVersion}/img/champion/{champion}");

assertThat(imageFetcher.setImgsSrcs(Arrays.asList(image1, image2), builder, latestVersion)).isEqualTo(0);
}
Version latestVersion = Version.patch("6.24.1");

@Test
void setsImagesSourcesWithValidUrl() {
Image image1 = new Image("Aatrox.png", "champion0.png", "champion", new byte[0], 0, 0, 48, 48);
Image image2 = new Image("Akali.png", "champion0.png", "champion", new byte[0], 96, 0, 48, 48);
assertThat(imageFetcher.setImgsSrcs(Arrays.asList(image1, image2), builder, latestVersion)).isEqualTo(0);
}

UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");
@Test
void withValidUrl() {
Image image1 = new Image("Aatrox.png", "champion0.png", "champion", new byte[0], 0, 0, 48, 48);
Image image2 = new Image("Akali.png", "champion0.png", "champion", new byte[0], 96, 0, 48, 48);

Version latestVersion = Version.patch("6.24.1");
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");

assertThat(imageFetcher.setImgsSrcs(Arrays.asList(image1, image2), builder, latestVersion)).isEqualTo(2);
}
Version latestVersion = Version.patch("6.24.1");

assertThat(imageFetcher.setImgsSrcs(Arrays.asList(image1, image2), builder, latestVersion)).isEqualTo(2);
}

@Test
void withNullVersion() {
Image image1 = new Image("Aatrox.png", "champion0.png", "champion", new byte[0], 0, 0, 48, 48);
Image image2 = new Image("Akali.png", "champion0.png", "champion", new byte[0], 96, 0, 48, 48);

@Test
void setImagesSourcesWithNullVersion() {
Image image1 = new Image("Aatrox.png", "champion0.png", "champion", new byte[0], 0, 0, 48, 48);
Image image2 = new Image("Akali.png", "champion0.png", "champion", new byte[0], 96, 0, 48, 48);
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");

UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");
assertThat(imageFetcher.setImgsSrcs(Arrays.asList(image1, image2), builder, null)).isEqualTo(0);
}

assertThat(imageFetcher.setImgsSrcs(Arrays.asList(image1, image2), builder, null)).isEqualTo(0);
}

@Test
void setsImageSourceWithInvalidUrl() {
Image image = new Image("Alistar.png", "champion0.png", "champion", new byte[0], 144, 0, 48, 48);
@Nested
@DisplayName("setImgSrc")
class ImgSrc {

UriComponentsBuilder builder = UriComponentsBuilder
.fromPath("/cdn/{latestVersion}/img/champion/{champion}");
@Test
void withInvalidUrl() {
Image image = new Image("Alistar.png", "champion0.png", "champion", new byte[0], 144, 0, 48, 48);

Version latestVersion = Version.patch("6.24.1");
UriComponentsBuilder builder = UriComponentsBuilder
.fromPath("/cdn/{latestVersion}/img/champion/{champion}");

assertThat(imageFetcher.setImgSrc(image, builder, latestVersion)).isEqualTo(0);
}
Version latestVersion = Version.patch("6.24.1");

@Test
void setsImageSourceWithValidUrl() {
Image image = new Image("Alistar.png", "champion0.png", "champion", new byte[0], 144, 0, 48, 48);
assertThat(imageFetcher.setImgSrc(image, builder, latestVersion)).isEqualTo(0);
}

UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");
@Test
void withValidUrl() {
Image image = new Image("Alistar.png", "champion0.png", "champion", new byte[0], 144, 0, 48, 48);

Version latestVersion = Version.patch("6.24.1");
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");

assertThat(imageFetcher.setImgSrc(image, builder, latestVersion)).isOne();
}
Version latestVersion = Version.patch("6.24.1");

assertThat(imageFetcher.setImgSrc(image, builder, latestVersion)).isOne();
}

@Test
void withNullVersion() {
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");

@Test
void setImageSourceWithNullVersion() {
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://ddragon.leagueoflegends.com/cdn/{latestVersion}/img/champion/{champion}");
Image image = new Image("Alistar.png", "champion0.png", "champion", new byte[0], 144, 0, 48, 48);

Image image = new Image("Alistar.png", "champion0.png", "champion", new byte[0], 144, 0, 48, 48);
assertThat(imageFetcher.setImgSrc(image, builder, null)).isEqualTo(0);
}

assertThat(imageFetcher.setImgSrc(image, builder, null)).isEqualTo(0);
}

}
Loading

0 comments on commit b5cd872

Please sign in to comment.