[Jguiraffe-developers] SF.net SVN: jguiraffe:[200] trunk/core/src
Brought to you by:
oheger
|
From: <oh...@us...> - 2011-07-02 15:32:26
|
Revision: 200
http://jguiraffe.svn.sourceforge.net/jguiraffe/?rev=200&view=rev
Author: oheger
Date: 2011-07-02 15:32:19 +0000 (Sat, 02 Jul 2011)
Log Message:
-----------
[3299754] Fixed a NPE in the dependency injection framework when looking up beans by class.
Modified Paths:
--------------
trunk/core/src/changes/changes.xml
trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/window/WindowBuilderData.java
trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/window/TestWindowBuilderData.java
Modified: trunk/core/src/changes/changes.xml
===================================================================
--- trunk/core/src/changes/changes.xml 2011-07-01 20:18:25 UTC (rev 199)
+++ trunk/core/src/changes/changes.xml 2011-07-02 15:32:19 UTC (rev 200)
@@ -1,3 +1,23 @@
+<!--
+
+ Copyright 2006-2011 The JGUIraffe Team.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!-- ===================================================================== -->
+<!-- $Id$ -->
+<!-- ===================================================================== -->
<document xmlns="http://maven.apache.org/changes/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/xsd/changes-1.0.0.xsd">
@@ -7,6 +27,10 @@
</properties>
<body>
<release version="1.1" date="in SVN" description="TBD">
+ <action dev="oheger" issue="3299754" type="fix">
+ Fixed a NullPointerException which can occur in the dependency injection
+ framework when looking up beans by classes rather than bean names.
+ </action>
</release>
<release version="1.0" date="2010-09-03" description="First release">
Modified: trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/window/WindowBuilderData.java
===================================================================
--- trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/window/WindowBuilderData.java 2011-07-01 20:18:25 UTC (rev 199)
+++ trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/window/WindowBuilderData.java 2011-07-02 15:32:19 UTC (rev 200)
@@ -15,6 +15,7 @@
*/
package net.sf.jguiraffe.gui.builder.window;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -260,9 +261,9 @@
*/
public void beanNames(Set<String> names)
{
- names.add(KEY_CURRENT_WINDOW);
- names.add(KEY_FORM_BEAN);
- names.add(KEY_PARENT_WINDOW);
+ addBeanName(names, KEY_CURRENT_WINDOW, getResultWindow());
+ addBeanName(names, KEY_FORM_BEAN, getFormBean());
+ addBeanName(names, KEY_PARENT_WINDOW, getParentWindow());
for (String name : windows.keySet())
{
@@ -342,4 +343,21 @@
return (context != null) ? (WindowBuilderData) context
.findVariable(CTX_KEY) : null;
}
+
+ /**
+ * Helper method for adding a bean name to a collection only if the bean is
+ * not <b>null</b>.
+ *
+ * @param col the collection
+ * @param name the name
+ * @param bean the bean
+ */
+ private static void addBeanName(Collection<String> col, String name,
+ Object bean)
+ {
+ if (bean != null)
+ {
+ col.add(name);
+ }
+ }
}
Modified: trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/window/TestWindowBuilderData.java
===================================================================
--- trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/window/TestWindowBuilderData.java 2011-07-01 20:18:25 UTC (rev 199)
+++ trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/window/TestWindowBuilderData.java 2011-07-02 15:32:19 UTC (rev 200)
@@ -115,17 +115,40 @@
}
/**
- * Tests querying the names of the supported beans.
+ * Initializes the properties of the test object with object references.
*/
+ private void initAssociatedObjects()
+ {
+ data.setFormBean(new Object());
+ data.setParentWindow(EasyMock.createNiceMock(Window.class));
+ data.setResultWindow(EasyMock.createNiceMock(Window.class));
+ }
+
+ /**
+ * Tests whether the correct bean names are returned if all involved objects
+ * are present.
+ */
@Test
- public void testBeanNames()
+ public void testBeanNamesWithObjectRefs()
{
+ initAssociatedObjects();
Set<String> names = new HashSet<String>();
data.beanNames(names);
checkBeanNames(names);
}
/**
+ * Tests beanNames() if object references are not set.
+ */
+ @Test
+ public void testBeanNamesNoObjectRefs()
+ {
+ Set<String> names = new HashSet<String>();
+ data.beanNames(names);
+ assertTrue("Got bean names", names.isEmpty());
+ }
+
+ /**
* Helper method for creating and initializing a bean store with data from
* the window builder data object.
*
@@ -159,6 +182,7 @@
@Test
public void testInitBeanStoreProviderNames()
{
+ initAssociatedObjects();
SimpleBeanStoreImpl store = setUpStore();
checkBeanNames(store.providerNames());
assertTrue("Instance key not found", store.providerNames().contains(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|