import freenet.keys.FreenetURI
import java.io.ByteArrayInputStream
import javax.imageio.ImageIO
+import javax.inject.Inject
/**
* [ImageLoader] implementation that uses a simple Guava [com.google.common.cache.Cache].
*/
-class DefaultImageLoader(private val freenetInterface: FreenetInterface) : ImageLoader {
+class DefaultImageLoader @Inject constructor(private val freenetInterface: FreenetInterface) : ImageLoader {
private val imageCache = CacheBuilder.newBuilder().build<String, LoadedImage>()
private val callback = object : FreenetInterface.BackgroundFetchCallback {
package net.pterodactylus.sone.core
+import com.google.inject.ImplementedBy
+
/**
* Component that loads images and supplies information about them.
*/
+@ImplementedBy(DefaultImageLoader::class)
interface ImageLoader {
fun toLoadedImage(link: String): LoadedImage?
--- /dev/null
+package net.pterodactylus.sone.core
+
+import com.google.inject.Guice.createInjector
+import net.pterodactylus.sone.test.bindMock
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.notNullValue
+import org.junit.Test
+
+/**
+ * Unit test for [ImageLoader].
+ */
+class ImageLoaderTest {
+
+ @Test
+ fun `default image loader can be loaded by guice`() {
+ val injector = createInjector(bindMock<FreenetInterface>())
+ assertThat(injector.getInstance(ImageLoader::class.java), notNullValue());
+ }
+
+}
package net.pterodactylus.sone.test
+import com.google.inject.Module
import org.mockito.ArgumentCaptor
import org.mockito.Mockito
inline fun <reified T : Any> mock(): T = Mockito.mock<T>(T::class.java)!!
inline fun <reified T : Any> capture(): ArgumentCaptor<T> = ArgumentCaptor.forClass(T::class.java)
+
+inline fun <reified T : Any> bind(implementation: T): Module =
+ Module { it!!.bind(T::class.java).toInstance(implementation) }
+
+inline fun <reified T : Any> bindMock(): Module =
+ Module { it!!.bind(T::class.java).toInstance(mock<T>()) }