Skip to content

Commit

Permalink
Fix all mike comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanenicolas committed Jul 21, 2014
1 parent 14f2ca2 commit 3002334
Show file tree
Hide file tree
Showing 62 changed files with 136 additions and 186 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local.properties
#Eclipse files
.project
.classpath
.checkstyle
.settings/

# IntelliJ IDEA files
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ env:


before_install:
- ls -la
- git subtree add guice https://github.com/stephanenicolas/google-guice snicolas-mburton-blender-after-merge
- git clone -b travis `git config --get remote.origin.url` target/travis

android:
Expand All @@ -19,4 +21,4 @@ android:

script:
- echo "Travis branch is $TRAVIS_BRANCH"
- if [ "$TRAVIS_BRANCH" == "master" -a "TRAVIS_PULL_REQUEST" == "false" ] ; then mvn deploy -P guice --settings target/travis/settings.xml ; else mvn install -Pguice --settings target/travis/settings.xml ; fi
- if [ "$TRAVIS_BRANCH" == "master" -a "TRAVIS_PULL_REQUEST" == "false" ] ; then mvn deploy --settings target/travis/settings.xml ; else mvn install --settings target/travis/settings.xml ; fi
2 changes: 1 addition & 1 deletion additional-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.roboguice</groupId>
<artifactId>roboguice-aggregator</artifactId>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void testShouldUseConstructorWithApplicationArgument() {
//GIVEN
Pojo instance = new Pojo();
//WHEN
RoboGuice.createBaseApplicationInjector(Robolectric.application).injectMembers(instance);
RoboGuice.getOrCreateBaseApplicationInjector(Robolectric.application).injectMembers(instance);
//THEN
//will only work if the TestModule could be loaded properly
assertThat( instance.getFoo(), notNullValue());
Expand Down
3 changes: 0 additions & 3 deletions astroboy/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
</activity>
<activity android:name=".activity.FightForcesOfEvilActivity" />

<meta-data
android:name="roboguice.annotations.packages"
android:value="astroboy" />
</application>

</manifest>
5 changes: 1 addition & 4 deletions astroboy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.roboguice</groupId>
<artifactId>roboguice-aggregator</artifactId>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down Expand Up @@ -84,9 +84,6 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<arg>-AguiceAnnotationDatabasePackageName=astroboy</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class AstroboyMasterConsoleTest {
@Before
public void setup() {
// Override the default RoboGuice module
astroboyMasterConsoleController = Robolectric.buildActivity(AstroboyMasterConsole.class);
astroboyMasterConsole = astroboyMasterConsoleController.get();
RoboGuice.overrideApplicationInjector(Robolectric.application, new MyTestModule());
astroboyMasterConsoleController = Robolectric.buildActivity(AstroboyMasterConsole.class);
astroboyMasterConsole = astroboyMasterConsoleController.get();
RoboGuice.overrideApplicationInjector(Robolectric.application, new MyTestModule());
astroboyMasterConsoleController.create().start();
}

Expand All @@ -47,16 +47,16 @@ public void teardown() {

@Test
public void clickOnBrushTeethTriggersRemoteControl() {
astroboyMasterConsole.brushTeethButton.callOnClick();
verify(astroboyRemoteControlMock).brushTeeth();
astroboyMasterConsole.brushTeethButton.callOnClick();
verify(astroboyRemoteControlMock).brushTeeth();
}


public class MyTestModule extends AbstractModule {
@Override
protected void configure() {
bind(Vibrator.class).toInstance(vibratorMock);
bind(Activity.class).toInstance(astroboyMasterConsole);
bind(Vibrator.class).toInstance(vibratorMock);
bind(Activity.class).toInstance(astroboyMasterConsole);
bind(AstroboyRemoteControl.class).toInstance(astroboyRemoteControlMock);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FightForcesOfEvilTest {
@Before
public void setup() {
// Override the default RoboGuice module
RoboGuice.overrideApplicationInjector(Robolectric.application, new MyTestModule());
RoboGuice.overrideApplicationInjector(Robolectric.application, new MyTestModule());
}

@After
Expand All @@ -38,9 +38,9 @@ public void teardown() {

@Test
public void createTriggersPunch() throws InterruptedException {
Robolectric.buildActivity(FightForcesOfEvilActivity.class).create().start();
Thread.sleep(6*1000);
verify(astroboyMock, Mockito.times(10)).punch();
Robolectric.buildActivity(FightForcesOfEvilActivity.class).create().start();
Thread.sleep(6*1000);
verify(astroboyMock, Mockito.times(10)).punch();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Astroboy1Test {
public void setup() {
RoboGuice.setUseAnnotationDatabases(false);
context = Robolectric.buildActivity(RoboActivity.class).create().get();
astroboy = RoboGuice.getInjector(context).getInstance(Astroboy.class);
astroboy = RoboGuice.createInjector(context).getInstance(Astroboy.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void teardown() {
public void brushingTeethShouldCausePhoneToVibrate() {

// get the astroboy instance
final Astroboy astroboy = RoboGuice.getInjector(context).getInstance(Astroboy.class);
final Astroboy astroboy = RoboGuice.createInjector(context).getInstance(Astroboy.class);

// do the thing
astroboy.brushTeeth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void teardown() {
public void brushingTeethShouldCausePhoneToVibrate() {

// get the astroboy instance
final Astroboy astroboy = RoboGuice.getInjector(Robolectric.application).getInstance(Astroboy.class);
final Astroboy astroboy = RoboGuice.createInjector(Robolectric.application).getInstance(Astroboy.class);

// do the thing
astroboy.brushTeeth();
Expand Down
14 changes: 2 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<groupId>org.roboguice</groupId>
<artifactId>roboguice-aggregator</artifactId>
<name>Aggregator</name>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
<packaging>pom</packaging>

<prerequisites>
<maven>3.1.1</maven>
</prerequisites>

<modules>
<module>guice</module>
<module>roboblender</module>
<module>roboguice</module>
<module>additional-tests</module>
Expand Down Expand Up @@ -321,15 +322,4 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<!-- To build Guice fork as well -->
<id>guice</id>
<modules>
<module>guice</module>
</modules>
</profile>
</profiles>

</project>
2 changes: 1 addition & 1 deletion roboblender/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.roboguice</groupId>
<artifactId>roboguice-aggregator</artifactId>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
</parent>

<properties>
Expand Down
10 changes: 0 additions & 10 deletions roboguice/.checkstyle

This file was deleted.

26 changes: 0 additions & 26 deletions roboguice/.classpath

This file was deleted.

4 changes: 2 additions & 2 deletions roboguice/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>roboguice-aggregator</artifactId>
<groupId>org.roboguice</groupId>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>roboguice</artifactId>
Expand Down Expand Up @@ -169,7 +169,7 @@
<dependency>
<groupId>org.roboguice</groupId>
<artifactId>roboblender</artifactId>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
5 changes: 2 additions & 3 deletions roboguice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.roboguice</groupId>
<artifactId>roboguice-aggregator</artifactId>
<version>3.0-alpha-3-SNAPSHOT</version>
<version>3.0-alpha-4-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down Expand Up @@ -230,8 +230,7 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<!-- Create RoboGuice uber jar.
Shade all dependencies, minimize and shrink. -->
<!-- Create RoboGuice uber jar. Shade all dependencies, minimize and shrink. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
26 changes: 13 additions & 13 deletions roboguice/src/main/java/roboguice/RoboGuice.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* There are two types of injectors:
*
* 1. The base application injector, which is not typically used directly by the user.
* 2. The ContextScopedInjector, which is obtained by calling {@link #getInjector(android.content.Context)}, and knows about
* 2. The ContextScopedInjector, which is obtained by calling {@link #createInjector(android.content.Context)}, and knows about
* your current context, whether it's an activity, service, or something else.
*
* BUG hashmap should also key off of stage and modules list
Expand Down Expand Up @@ -76,7 +76,7 @@ private RoboGuice() {
/**
* Return the cached Injector instance for this application, or create a new one if necessary.
*/
public static Injector createBaseApplicationInjector(Application application) {
public static Injector getOrCreateBaseApplicationInjector(Application application) {
Injector rtrn = injectors.get(application);
if( rtrn!=null )
return rtrn;
Expand All @@ -86,7 +86,7 @@ public static Injector createBaseApplicationInjector(Application application) {
if( rtrn!=null )
return rtrn;

return createBaseApplicationInjector(application, DEFAULT_STAGE);
return getOrCreateBaseApplicationInjector(application, DEFAULT_STAGE);
}
}

Expand All @@ -106,7 +106,7 @@ public static Injector createBaseApplicationInjector(Application application) {
* to avoid polluting our other tests with your custom injector. Don't do this in your real application though.
* <b>One of RoboGuice's entry points</b>.
*/
public static Injector createBaseApplicationInjector(final Application application, Stage stage, Module... modules ) {
public static Injector getOrCreateBaseApplicationInjector(final Application application, Stage stage, Module... modules ) {
final Stopwatch stopwatch = new Stopwatch();
synchronized (RoboGuice.class) {
initializeAnnotationDatabaseFinderAndHierarchyTraversalFilterFactory(application);
Expand All @@ -121,7 +121,7 @@ public static Injector createBaseApplicationInjector(final Application applicati
* RoboGuice.overrideApplicationInjector( app, new TestModule() );
*
* @see com.google.inject.util.Modules#override(com.google.inject.Module...)
* @see roboguice.RoboGuice#createBaseApplicationInjector(android.app.Application, com.google.inject.Stage, com.google.inject.Module...)
* @see roboguice.RoboGuice#getOrCreateBaseApplicationInjector(android.app.Application, com.google.inject.Stage, com.google.inject.Module...)
* @see roboguice.RoboGuice#newDefaultRoboModule(android.app.Application)
* @see roboguice.RoboGuice#DEFAULT_STAGE
*
Expand All @@ -130,7 +130,7 @@ public static Injector createBaseApplicationInjector(final Application applicati
*/
public static Injector overrideApplicationInjector(final Application application, Module... overrideModules) {
synchronized (RoboGuice.class) {
final List<Module> baseModules = getModulesFromManifest(application);
final List<Module> baseModules = extractModulesFromManifest(application);
final Injector rtrn = Guice.createInjector(DEFAULT_STAGE, Modules.override(baseModules).with(overrideModules));
injectors.put(application,rtrn);
return rtrn;
Expand All @@ -141,17 +141,17 @@ public static Injector overrideApplicationInjector(final Application application
* Return the cached Injector instance for this application, or create a new one if necessary.
* <b>One of RoboGuice's entry points</b>.
*/
public static Injector createBaseApplicationInjector(Application application, Stage stage) {
public static Injector getOrCreateBaseApplicationInjector(Application application, Stage stage) {
final Stopwatch stopwatch = new Stopwatch();

synchronized (RoboGuice.class) {
initializeAnnotationDatabaseFinderAndHierarchyTraversalFilterFactory(application);
final List<Module> modules = getModulesFromManifest(application);
final List<Module> modules = extractModulesFromManifest(application);
return createGuiceInjector(application, stage, stopwatch, modules.toArray(new Module[modules.size()]));
}
}

private static List<Module> getModulesFromManifest(Application application) {
private static List<Module> extractModulesFromManifest(Application application) {
try {
final ArrayList<Module> modules = new ArrayList<Module>();

Expand Down Expand Up @@ -191,16 +191,16 @@ private static Injector createGuiceInjector(final Application application, Stage
}
}

public static RoboInjector getInjector(Context context) {
public static RoboInjector createInjector(Context context) {
final Application application = (Application)context.getApplicationContext();
return new ContextScopedRoboInjector(context, createBaseApplicationInjector(application));
return new ContextScopedRoboInjector(context, getOrCreateBaseApplicationInjector(application));
}

/**
* A shortcut for RoboGuice.getInjector(context).injectMembers(o);
*/
public static <T> T injectMembers( Context context, T t ) {
getInjector(context).injectMembers(t);
createInjector(context).injectMembers(t);
return t;
}

Expand Down Expand Up @@ -243,7 +243,7 @@ protected static ViewListener getViewListener( final Application application ) {
}

public static void destroyInjector(Context context) {
final RoboInjector injector = getInjector(context);
final RoboInjector injector = createInjector(context);
injector.getInstance(EventManager.class).destroy();
//noinspection SuspiciousMethodCalls
injectors.remove(context); // it's okay, Context is an Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class RoboAccountAuthenticatorActivity extends AccountAuthenticatorActivi

@Override
protected void onCreate(Bundle savedInstanceState) {
final RoboInjector injector = RoboGuice.getInjector(this);
final RoboInjector injector = RoboGuice.createInjector(this);
eventManager = injector.getInstance(EventManager.class);
injector.injectMembersWithoutViews(this);
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -142,7 +142,7 @@ public void onConfigurationChanged(Configuration newConfig) {
@Override
public void onContentChanged() {
super.onContentChanged();
RoboGuice.getInjector(this).injectViewMembers(this);
RoboGuice.createInjector(this).injectViewMembers(this);
eventManager.fire(new OnContentChangedEvent(this));
}

Expand Down
Loading

0 comments on commit 3002334

Please sign in to comment.