import net.pterodactylus.sone.text.LinkType.USK
import org.bitpedia.util.Base32
import java.net.MalformedURLException
+import javax.inject.*
/**
* [Parser] implementation that can recognize Freenet URIs.
*/
-class SoneTextParser(private val soneProvider: SoneProvider?, private val postProvider: PostProvider?) {
+class SoneTextParser @Inject constructor(private val soneProvider: SoneProvider?, private val postProvider: PostProvider?) {
fun parse(source: String, context: SoneTextParserContext?) =
source.split("\n")
package net.pterodactylus.sone.text;
+import static com.google.inject.Guice.createInjector;
import static java.lang.String.format;
+import static net.pterodactylus.sone.test.GuiceKt.supply;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isIn;
import net.pterodactylus.sone.database.SoneProvider;
import com.google.common.base.Optional;
+import com.google.inject.Injector;
import kotlin.jvm.functions.Function1;
import org.junit.Test;
return text.toString();
}
+ @Test
+ public void parserCanBeCreatedByGuice() {
+ Injector injector = createInjector(
+ supply(SoneProvider.class).byMock(),
+ supply(PostProvider.class).byMock()
+ );
+ assertThat(injector.getInstance(SoneTextParser.class), notNullValue());
+ }
+
/**
* Mock Sone provider.
*/
import com.google.inject.Injector
import com.google.inject.Module
+import org.mockito.*
import javax.inject.Provider
import kotlin.reflect.KClass
override fun byInstance(instance: T) = Module { it.bind(javaClass).toProvider(Provider<T> { instance }) }
override fun byProvider(provider: com.google.inject.Provider<T>) = Module { it.bind(javaClass).toProvider(provider) }
override fun byProvider(provider: Class<Provider<T>>) = Module { it.bind(javaClass).toProvider(provider) }
+ override fun byMock() = Module { it.bind(javaClass).toInstance(Mockito.mock(javaClass)) }
}
interface Source<T : Any> {
fun byInstance(instance: T): Module
fun byProvider(provider: com.google.inject.Provider<T>): Module
fun byProvider(provider: Class<Provider<T>>): Module
+ fun byMock(): Module
}