You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by li...@apache.org on 2009/02/18 09:54:20 UTC
svn commit: r745436 - in /incubator/shindig/trunk/java/gadgets/src:
main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
test/java/org/apache/shindig/gadgets/GadgetFeatureRegistryTest.java
Author: lindner
Date: Wed Feb 18 08:54:20 2009
New Revision: 745436
URL: http://svn.apache.org/viewvc?rev=745436&view=rev
Log:
SHINDIG-924 | Patch from Bob Evans | Should not allow registration of two features with the same name
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetFeatureRegistryTest.java
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java?rev=745436&r1=745435&r2=745436&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java Wed Feb 18 08:54:20 2009
@@ -101,6 +101,10 @@
public void register(GadgetFeature feature) {
Preconditions.checkState(!isLocked(), "registry is locked and can no longer be changed!");
+ if (features.containsKey(feature.getName())) {
+ throw new IllegalArgumentException("Trying to enter the same feature twice: "+feature.getName());
+ }
+
if (logger.isLoggable(Level.FINE)) logger.fine("Registering feature: " + feature.getName());
if (isCore(feature)) {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetFeatureRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetFeatureRegistryTest.java?rev=745436&r1=745435&r2=745436&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetFeatureRegistryTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetFeatureRegistryTest.java Wed Feb 18 08:54:20 2009
@@ -19,21 +19,17 @@
package org.apache.shindig.gadgets;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-
-import java.util.Collections;
-
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -133,4 +129,23 @@
assertTrue(feature + " not returned.", found.contains(feature));
}
}
+
+ @Test
+ public void duplicateFeaturesRejected() throws Exception {
+ int expectedFeaturesInRegistry = 2;
+ registry.register(makeFeature(FEATURE_NAME, CONTENT, DEP_NAME));
+ try {
+ registry.register(makeFeature(FEATURE_NAME, CONTENT, DEP_NAME));
+ fail("Should have thrown IllegalArgumentException for duplicate name registration");
+ } catch (IllegalArgumentException e) {
+ }
+ Collection<GadgetFeature> features
+ = registry.getFeatures(Arrays.asList(FEATURE_NAME));
+ assertEquals(expectedFeaturesInRegistry, features.size());
+ // Order must be preserved.
+ Iterator<GadgetFeature> i = features.iterator();
+ assertEquals(CORE_NAME, i.next().getName());
+ assertEquals(FEATURE_NAME, i.next().getName());
+ }
+
}