-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
The following unit test fails to excute due to a "java.lang.ClassCastException: org.codejargon.feather.Feather$1 cannot be cast to org.codejargon.feather.Feather
"
I think line 32 of Feather.java should be "return Feather.this;" instead of "return this;"
Content of InjectedFeatherTest.java
package org.codejargon.feather;
import static org.junit.Assert.*;
import javax.inject.Inject;
import javax.inject.Provider;
import org.junit.Test;
public class InjectedFeatherTest {
@Test
public void featherProviderInjection() {
Feather feather = Feather.with();
InjectedFeatherProvider injected = feather
.instance(InjectedFeatherProvider.class);
assertEquals(feather, injected.feather());
}
@Test
public void featherInjection() {
Feather feather = Feather.with();
InjectedFeather injected = feather.instance(InjectedFeather.class);
assertEquals(feather, injected.feather());
}
@Test
public void featherInjectionThroughModule() {
Feather feather = Feather.with(new Module());
InjectedFeather injected1 = feather.instance(InjectedFeather.class);
assertEquals(feather, injected1.feather());
InjectedFeatherProvider injected2 = feather
.instance(InjectedFeatherProvider.class);
assertEquals(feather, injected2.feather());
}
// ------------------------------------------------------------------
public static class InjectedFeatherProvider {
private final Feather injected;
@Inject
public InjectedFeatherProvider(Provider<Feather> f) {
injected = f.get();
}
Feather feather() {
return injected;
}
}
public static class InjectedFeather {
private final Feather injected;
@Inject
public InjectedFeather(Feather f) {
injected = f;
}
Feather feather() {
return injected;
}
}
public static class Module {
@Provides
public InjectedFeather providesInjectedFeather(Feather f) {
return new InjectedFeather(f);
}
@Provides
public InjectedFeatherProvider providesInjectedFeatherProvider(
Provider<Feather> f) {
return new InjectedFeatherProvider(f);
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels