package com.drumonii.loltrollbuild.riot.api;

import com.drumonii.loltrollbuild.model.Version;
import com.drumonii.loltrollbuild.model.image.Image;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.Arrays;
import java.util.List;

import static com.drumonii.loltrollbuild.config.Profiles.TESTING;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = { "riot.api.key=API_KEY", "spring.cache.type=simple" })
@ActiveProfiles(TESTING)
public class ImageFetcherTest {

	@Autowired
	private ImageFetcher imageFetcher;

	@Mock
	private UriComponentsBuilder builder;

	@Mock
	private UriComponents uriComponents;

	@Before
	public void before() {

		MockitoAnnotations.initMocks(this);
	}

	@Test
	public void setImgsSrcs() throws Exception {
		Image image1 = new Image("arctichare.png", "arctichare.png", "group", new byte[0], 144, 48, 48, 48);
		Image image2 = new Image("fruits.png", "fruits.png", "group", new byte[0], 144, 48, 48, 48);
		List<Image> images = Arrays.asList(image1, image2);

		Version latestVersion = new Version("1.0.0");

		given(builder.buildAndExpand(anyString(), anyString()))
				.willReturn(uriComponents);
		for (Image image : images) {
			given(uriComponents.toUriString())
					.willReturn(image.getFull());
		}
		assertThat(imageFetcher.setImgsSrcs(images, builder, latestVersion)).isEqualTo(0);

		given(builder.buildAndExpand(anyString(), anyString()))
				.willReturn(uriComponents);
		for (Image image : images) {
			given(uriComponents.toUriString())
					.willReturn("http://homepages.cae.wisc.edu/~ece533/images/" + image.getFull());
		}
		assertThat(imageFetcher.setImgsSrcs(images, builder, latestVersion)).isEqualTo(2);
	}

	@Test
	public void setImgSrc() throws Exception {
		Image image = new Image("monarch.png", "monarch0.png", "group", new byte[0], 144, 48, 48, 48);

		Version latestVersion = new Version("1.0.0");

		given(builder.buildAndExpand(anyString(), anyString()))
				.willReturn(uriComponents);
		given(uriComponents.toUriString())
				.willReturn(image.getFull());
		assertThat(imageFetcher.setImgSrc(image, builder, latestVersion)).isEqualTo(0);

		given(builder.buildAndExpand(anyString(), anyString()))
				.willReturn(uriComponents);
		given(uriComponents.toUriString())
				.willReturn("http://homepages.cae.wisc.edu/~ece533/images/" + image.getFull());
		assertThat(imageFetcher.setImgSrc(image, builder, latestVersion)).isOne();
	}

}
@@ -145,33 +145,8 @@
 ge;%0A
-import org.junit.Before;%0A
 impo
@@ -216,20 +216,27 @@
 mockito.
+Inject
 Mock
+s
 ;%0Aimport
@@ -256,257 +256,49 @@
 Mock
-itoAnnotations;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.context.SpringBootTest;%0Aimport org.springframework.test.context.ActiveProfiles;%0Aimport org.springframework.test.context.junit4.Spring
+;%0Aimport org.mockito.runners.MockitoJUnit
 Runn
@@ -464,74 +464,8 @@
 t;%0A%0A
-import static com.drumonii.loltrollbuild.config.Profiles.TESTING;%0A
 impo
@@ -612,271 +612,42 @@
 ng;%0A
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;%0A%0A@RunWith(SpringRunner.class)%0A@SpringBootTest(webEnvironment = RANDOM_PORT, properties = %7B %22riot.api.key=API_KEY%22, %22spring.cache.type=simple%22 %7D)%0A@ActiveProfiles(TESTING
+%0A@RunWith(MockitoJUnitRunner.class
 )%0Apu
@@ -683,17 +683,19 @@
 %0A%0A%09@
-Autowired
+InjectMocks
 %0A%09pr
@@ -825,84 +825,8 @@
 s;%0A%0A
-%09@Before%0A%09public void before() %7B%0A%0A%09%09MockitoAnnotations.initMocks(this);%0A%09%7D%0A%0A
 %09@Te

Convert ImageFetcherTest to use InjectMocks