Added tests for getInstance() and getFactory() convenience methods.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@92 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/guice.iws b/guice.iws
index 0a7ade3..5c37c1e 100644
--- a/guice.iws
+++ b/guice.iws
@@ -18,7 +18,6 @@
</component>
<component name="ChangeListManager">
<list default="true" name="Default" comment="">
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/inject/AbstractModule.java" afterPath="$PROJECT_DIR$/src/com/google/inject/AbstractModule.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/guice.iws" afterPath="$PROJECT_DIR$/guice.iws" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/test/com/google/inject/ContainerTest.java" afterPath="$PROJECT_DIR$/test/com/google/inject/ContainerTest.java" />
</list>
@@ -193,7 +192,7 @@
<file leaf-file-name="ContainerBuilder.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/inject/ContainerBuilder.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="654" column="32" selection-start="19807" selection-end="19807" vertical-scroll-proportion="0.016236868">
+ <state line="654" column="32" selection-start="19807" selection-end="19807" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
@@ -202,7 +201,7 @@
<file leaf-file-name="ContainerImpl.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/inject/ContainerImpl.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="595" column="0" selection-start="18754" selection-end="18754" vertical-scroll-proportion="0.016236868">
+ <state line="595" column="0" selection-start="18754" selection-end="18754" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
@@ -211,7 +210,7 @@
<file leaf-file-name="ErrorMessages.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/inject/ErrorMessages.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="41" column="6" selection-start="1346" selection-end="1346" vertical-scroll-proportion="0.016236868">
+ <state line="41" column="6" selection-start="1346" selection-end="1346" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
@@ -220,7 +219,7 @@
<file leaf-file-name="PerformanceComparison.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/com/google/inject/PerformanceComparison.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="47" column="0" selection-start="1758" selection-end="1758" vertical-scroll-proportion="0.016236868">
+ <state line="47" column="0" selection-start="1758" selection-end="1758" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
@@ -229,16 +228,16 @@
<file leaf-file-name="Queries.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/inject/intercept/Queries.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="150" column="5" selection-start="3888" selection-end="3888" vertical-scroll-proportion="0.6513849">
+ <state line="150" column="5" selection-start="3888" selection-end="3888" vertical-scroll-proportion="1.1216216">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="AllTests.java" pinned="false" current="false" current-in-tab="false">
+ <file leaf-file-name="AllTests.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test/com/google/inject/AllTests.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="32" column="13" selection-start="1115" selection-end="1115" vertical-scroll-proportion="0.1461318">
+ <state line="32" column="13" selection-start="1115" selection-end="1115" vertical-scroll-proportion="0.25844595">
<folding />
</state>
</provider>
@@ -247,7 +246,7 @@
<file leaf-file-name="Container.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/inject/Container.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="127" column="0" selection-start="3268" selection-end="3268" vertical-scroll-proportion="0.9274117">
+ <state line="127" column="0" selection-start="3268" selection-end="3268" vertical-scroll-proportion="1.6097972">
<folding />
</state>
</provider>
@@ -256,16 +255,16 @@
<file leaf-file-name="ContainerTest.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/com/google/inject/ContainerTest.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="34" column="0" selection-start="970" selection-end="970" vertical-scroll-proportion="0.016236868">
+ <state line="43" column="0" selection-start="1571" selection-end="1571" vertical-scroll-proportion="0.7753378">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="AbstractModule.java" pinned="false" current="true" current-in-tab="true">
+ <file leaf-file-name="AbstractModule.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/inject/AbstractModule.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="67" column="0" selection-start="1893" selection-end="1893" vertical-scroll-proportion="0.016236868">
+ <state line="67" column="0" selection-start="1893" selection-end="1893" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
@@ -497,7 +496,7 @@
<showLibraryContents PackagesPane="false" />
<hideEmptyPackages />
<abbreviatePackageNames />
- <showStructure Favorites="false" PackagesPane="false" Scope="false" ProjectPane="false" />
+ <showStructure ProjectPane="false" PackagesPane="false" Scope="false" Favorites="false" />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
@@ -579,6 +578,38 @@
<option name="Make" value="true" />
</method>
</tempConfiguration>
+ <configuration default="true" type="Applet" factoryName="Applet">
+ <module name="" />
+ <option name="MAIN_CLASS_NAME" />
+ <option name="HTML_FILE_NAME" />
+ <option name="HTML_USED" value="false" />
+ <option name="WIDTH" value="400" />
+ <option name="HEIGHT" value="300" />
+ <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
+ <option name="VM_PARAMETERS" />
+ <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+ <option name="ALTERNATIVE_JRE_PATH" />
+ </configuration>
+ <configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
+ <option name="MAIN_CLASS_NAME" />
+ <option name="VM_PARAMETERS" />
+ <option name="PROGRAM_PARAMETERS" />
+ <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+ <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+ <option name="ALTERNATIVE_JRE_PATH" />
+ <option name="ENABLE_SWING_INSPECTOR" value="false" />
+ <module name="" />
+ <method>
+ <option name="Make" value="true" />
+ </method>
+ </configuration>
+ <configuration default="true" type="Remote" factoryName="Remote">
+ <option name="USE_SOCKET_TRANSPORT" value="true" />
+ <option name="SERVER_MODE" value="false" />
+ <option name="SHMEM_ADDRESS" value="javadebug" />
+ <option name="HOST" value="localhost" />
+ <option name="PORT" value="5005" />
+ </configuration>
<configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@@ -598,38 +629,6 @@
<option name="Make" value="true" />
</method>
</configuration>
- <configuration default="true" type="Remote" factoryName="Remote">
- <option name="USE_SOCKET_TRANSPORT" value="true" />
- <option name="SERVER_MODE" value="false" />
- <option name="SHMEM_ADDRESS" value="javadebug" />
- <option name="HOST" value="localhost" />
- <option name="PORT" value="5005" />
- </configuration>
- <configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
- <option name="MAIN_CLASS_NAME" />
- <option name="VM_PARAMETERS" />
- <option name="PROGRAM_PARAMETERS" />
- <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
- <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
- <option name="ALTERNATIVE_JRE_PATH" />
- <option name="ENABLE_SWING_INSPECTOR" value="false" />
- <module name="" />
- <method>
- <option name="Make" value="true" />
- </method>
- </configuration>
- <configuration default="true" type="Applet" factoryName="Applet">
- <module name="" />
- <option name="MAIN_CLASS_NAME" />
- <option name="HTML_FILE_NAME" />
- <option name="HTML_USED" value="false" />
- <option name="WIDTH" value="400" />
- <option name="HEIGHT" value="300" />
- <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
- <option name="VM_PARAMETERS" />
- <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
- <option name="ALTERNATIVE_JRE_PATH" />
- </configuration>
<configuration default="false" name="PerformanceComparison" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" value="com.google.inject.PerformanceComparison" />
<option name="VM_PARAMETERS" value="-server" />
@@ -753,7 +752,7 @@
<option name="UPDATE_RUN_STATUS" value="false" />
<option name="UPDATE_RECURSIVELY" value="true" />
<option name="MERGE_DRY_RUN" value="false" />
- <configuration useDefault="true">/home/crazybob/.subversion</configuration>
+ <configuration useDefault="true">/Users/crazybob/.subversion</configuration>
<remoteStatus />
<upgradeMode>auto</upgradeMode>
</component>
@@ -772,38 +771,38 @@
</todo-panel>
</component>
<component name="ToolWindowManager">
- <frame x="4" y="44" width="1916" height="1156" extended-state="0" />
- <editor active="true" />
+ <frame x="4" y="22" width="1916" height="1178" extended-state="6" />
+ <editor active="false" />
<layout>
<window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="CVS" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="IDEtalk" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3336904" order="3" />
- <window_info id="Mach" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32919848" order="9" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="7" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.15854311" order="0" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.29509714" order="1" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.16236559" order="1" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4745606" order="10" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="6" />
- <window_info id="Profile" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32890996" order="13" />
<window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="11" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.14623655" order="1" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3282876" order="8" />
- <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.39962998" order="2" />
+ <window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.39962998" order="2" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" />
<window_info id="File View" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="6" />
- <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.39978448" order="0" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32639545" order="4" />
+ <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.39978448" order="0" />
<window_info id="IDEtalk Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.34531695" order="12" />
+ <window_info id="Mach" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32919848" order="9" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="0" />
<window_info id="Favorites" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="4" />
<window_info id="Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="5" />
<window_info id="Compare Directories" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32977018" order="3" />
<window_info id="Web" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" />
<window_info id="EJB" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="3" />
+ <window_info id="Profile" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32890996" order="13" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="5" />
</layout>
</component>
@@ -934,63 +933,63 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/inject/ContainerBuilder.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="654" column="32" selection-start="19807" selection-end="19807" vertical-scroll-proportion="0.016236868">
+ <state line="654" column="32" selection-start="19807" selection-end="19807" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/inject/ContainerImpl.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="595" column="0" selection-start="18754" selection-end="18754" vertical-scroll-proportion="0.016236868">
+ <state line="595" column="0" selection-start="18754" selection-end="18754" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/inject/ErrorMessages.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="41" column="6" selection-start="1346" selection-end="1346" vertical-scroll-proportion="0.016236868">
+ <state line="41" column="6" selection-start="1346" selection-end="1346" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/com/google/inject/PerformanceComparison.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="47" column="0" selection-start="1758" selection-end="1758" vertical-scroll-proportion="0.016236868">
+ <state line="47" column="0" selection-start="1758" selection-end="1758" vertical-scroll-proportion="0.028716216">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/inject/intercept/Queries.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="150" column="5" selection-start="3888" selection-end="3888" vertical-scroll-proportion="0.6513849">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/test/com/google/inject/AllTests.java">
- <provider selected="true" editor-type-id="text-editor">
- <state line="32" column="13" selection-start="1115" selection-end="1115" vertical-scroll-proportion="0.1461318">
+ <state line="150" column="5" selection-start="3888" selection-end="3888" vertical-scroll-proportion="1.1216216">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/inject/Container.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="127" column="0" selection-start="3268" selection-end="3268" vertical-scroll-proportion="0.9274117">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/test/com/google/inject/ContainerTest.java">
- <provider selected="true" editor-type-id="text-editor">
- <state line="34" column="0" selection-start="970" selection-end="970" vertical-scroll-proportion="0.016236868">
+ <state line="127" column="0" selection-start="3268" selection-end="3268" vertical-scroll-proportion="1.6097972">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/inject/AbstractModule.java">
<provider selected="true" editor-type-id="text-editor">
- <state line="67" column="0" selection-start="1893" selection-end="1893" vertical-scroll-proportion="0.016236868">
+ <state line="67" column="0" selection-start="1893" selection-end="1893" vertical-scroll-proportion="0.028716216">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/test/com/google/inject/ContainerTest.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="43" column="0" selection-start="1571" selection-end="1571" vertical-scroll-proportion="0.7753378">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/test/com/google/inject/AllTests.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="32" column="13" selection-start="1115" selection-end="1115" vertical-scroll-proportion="0.25844595">
<folding />
</state>
</provider>
diff --git a/test/com/google/inject/ContainerTest.java b/test/com/google/inject/ContainerTest.java
index ee699fe..b22a1ee 100644
--- a/test/com/google/inject/ContainerTest.java
+++ b/test/com/google/inject/ContainerTest.java
@@ -25,14 +25,25 @@
*/
public class ContainerTest extends TestCase {
- public void testFactoryMethods() {
+ public void testFactoryMethods() throws ContainerCreationException {
+ Singleton singleton = new Singleton();
+
ContainerBuilder builder = new ContainerBuilder();
- builder.bind(Widget.class).in(Scopes.CONTAINER_SCOPE);
+ builder.bind(Singleton.class).to(singleton);
+ Container container = builder.create(true);
-
+ assertSame(singleton,
+ container.getFactory(Key.get(Singleton.class)).get());
+ assertSame(singleton, container.getFactory(Singleton.class).get());
+ assertSame(singleton,
+ container.getFactory(new TypeLiteral<Singleton>() {}).get());
+ assertSame(singleton, container.getInstance(Key.get(Singleton.class)));
+ assertSame(singleton, container.getInstance(Singleton.class));
+ assertSame(singleton,
+ container.getInstance(new TypeLiteral<Singleton>() {}));
}
- static class Widget {}
+ static class Singleton {}
public void testInjection() throws ContainerCreationException {
Container container = createFooContainer();