import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
+@Singleton
public class IdentityAccessor extends ReflectionAccessor {
/** The core. */
* @param core
* The core
*/
+ @Inject
public IdentityAccessor(Core core) {
this.core = core;
}
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.sameInstance;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import net.pterodactylus.sone.freenet.wot.IdentityManager;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
Matchers.<Object>is(identity.hashCode()));
}
+ @Test
+ public void accessorCanBeCreatedByGuice() {
+ Injector injector = Guice.createInjector(
+ new Module() {
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Core.class).toInstance(mock(Core.class));
+ }
+ }
+ );
+ assertThat(injector.getInstance(IdentityAccessor.class), notNullValue());
+ }
+
+ @Test
+ public void accessorIsCreatedAsSingleton() {
+ Injector injector = Guice.createInjector(
+ new Module() {
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Core.class).toInstance(mock(Core.class));
+ }
+ }
+ );
+ IdentityAccessor firstAccessor = injector.getInstance(IdentityAccessor.class);
+ IdentityAccessor secondAccessor = injector.getInstance(IdentityAccessor.class);
+ assertThat(firstAccessor, sameInstance(secondAccessor));
+ }
+
}