Author: ieb
Date: Wed Jul 23 10:47:52 2008
New Revision: 679143

URL: http://svn.apache.org/viewvc?rev=679143&view=rev
Log:
Added a tests to cover untested areas of the code.

Added:
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java
Modified:
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java?rev=679143&r1=679142&r2=679143&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java
 Wed Jul 23 10:47:52 2008
@@ -33,6 +33,7 @@
 import org.apache.shindig.social.core.model.NameImpl;
 import org.apache.shindig.social.core.model.PersonImpl;
 import org.apache.shindig.social.core.model.PhoneImpl;
+import org.apache.shindig.social.core.util.BeanJsonLibConversionException;
 import org.apache.shindig.social.core.util.BeanJsonLibConverter;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Address;
@@ -49,25 +50,22 @@
 
 public class BeanJsonLibConverterTest extends TestCase {
 
-  private static final Log log = LogFactory
-      .getLog(BeanJsonLibConverterTest.class);
+  private static final Log log = 
LogFactory.getLog(BeanJsonLibConverterTest.class);
   // taken from opensocial-reference/person.js
-  private static final String[] PERSON_FIELDS = { "id", "name", "nickname",
-      "thumbnailUrl", "profileUrl", "currentLocation", "addresses", "emails",
-      "phoneNumbers", "aboutMe", "status", "profileSong", "profileVideo",
-      "gender", "sexualOrientation", "relationshipStatus", "age",
-      "dateOfBirth", "bodyType", "ethnicity", "smoker", "drinker", "children",
-      "pets", "livingArrangement", "timeZone", "languagesSpoken", "jobs",
-      "jobInterests", "schools", "interests", "urls", "music", "movies",
-      "tvShows", "books", "activities", "sports", "heroes", "quotes", "cars",
-      "food", "turnOns", "turnOffs", "tags", "romance", "scaredOf",
-      "happiestWhen", "fashion", "humor", "lookingFor", "religion",
-      "politicalViews", "hasApp", "networkPresence" };
+  private static final String[] PERSON_FIELDS = { "id", "name", "nickname", 
"thumbnailUrl",
+      "profileUrl", "currentLocation", "addresses", "emails", "phoneNumbers", 
"aboutMe", "status",
+      "profileSong", "profileVideo", "gender", "sexualOrientation", 
"relationshipStatus", "age",
+      "dateOfBirth", "bodyType", "ethnicity", "smoker", "drinker", "children", 
"pets",
+      "livingArrangement", "timeZone", "languagesSpoken", "jobs", 
"jobInterests", "schools",
+      "interests", "urls", "music", "movies", "tvShows", "books", 
"activities", "sports", "heroes",
+      "quotes", "cars", "food", "turnOns", "turnOffs", "tags", "romance", 
"scaredOf",
+      "happiestWhen", "fashion", "humor", "lookingFor", "religion", 
"politicalViews", "hasApp",
+      "networkPresence" };
 
   // taken from opensocial-reference/name.js
-  private static final String[] NAME_FIELDS = { "familyName", "givenName",
-      "additionalName", "honorificPrefix", "honorificSuffix", "unstructured"};
-  
+  private static final String[] NAME_FIELDS = { "familyName", "givenName", 
"additionalName",
+      "honorificPrefix", "honorificSuffix", "unstructured" };
+
   private Person johnDoe;
   private Activity activity;
 
@@ -80,21 +78,18 @@
   public void setUp() throws Exception {
     super.setUp();
     johnDoe = new PersonImpl("johnDoeId", new NameImpl("John Doe"));
-    johnDoe.setPhoneNumbers(Lists.<Phone> newArrayList(new PhoneImpl(
-        "+33H000000000", "home"), new PhoneImpl("+33M000000000", "mobile"),
-        new PhoneImpl("+33W000000000", "work")));
+    johnDoe.setPhoneNumbers(Lists.<Phone> newArrayList(new 
PhoneImpl("+33H000000000", "home"),
+        new PhoneImpl("+33M000000000", "mobile"), new 
PhoneImpl("+33W000000000", "work")));
 
-    johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl(
-        "My home address")));
+    johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl("My home 
address")));
 
-    johnDoe.setEmails(Lists.<Email> newArrayList(new EmailImpl(
-        "[EMAIL PROTECTED]", "work"),
+    johnDoe.setEmails(Lists.<Email> newArrayList(new EmailImpl("[EMAIL 
PROTECTED]", "work"),
         new EmailImpl("[EMAIL PROTECTED]", "home")));
 
     activity = new ActivityImpl("activityId", johnDoe.getId());
 
-    activity.setMediaItems(Lists.<MediaItem> newArrayList(new MediaItemImpl(
-        "image/jpg", MediaItem.Type.IMAGE, "http://foo.bar";)));
+    activity.setMediaItems(Lists.<MediaItem> newArrayList(new 
MediaItemImpl("image/jpg",
+        MediaItem.Type.IMAGE, "http://foo.bar";)));
 
     Injector injector = Guice.createInjector(new JsonLibTestsGuiceModule());
     beanJsonConverter = injector.getInstance(BeanJsonLibConverter.class);
@@ -105,19 +100,15 @@
 
   public static class SpecialPerson extends PersonImpl {
     public static final String[] OPTIONALFIELDS = {};
-    public static final String[] NULLFIELDS = { "jobInterests", "nickname",
-        "romance", "religion", "timeZone", "relationshipStatus", "tags",
-        "networkPresence", "books", "quotes", "phoneNumbers",
-        "languagesSpoken", "activities", "jobs", "dateOfBirth", "profileVideo",
-        "bodyType", "urls", "schools", "music", "addresses",
-        "livingArrangement", "thumbnailUrl", "humor", "sports", "scaredOf",
-        "movies", "age", "pets", "hasApp", "turnOffs", "gender", "fashion",
-        "drinker", "aboutMe", "children", "sexualOrientation", "heroes",
-        "profileSong", "lookingFor", "cars", "turnOns", "tvShows",
-        "profileUrl", "status", "currentLocation", "smoker", "happiestWhen",
-        "ethnicity", "food", "emails", "politicalViews", "interests",
-        "familyName", "honorificSuffix", "additionalName", "honorificPrefix",
-        "givenName" };
+    public static final String[] NULLFIELDS = { "jobInterests", "nickname", 
"romance", "religion",
+        "timeZone", "relationshipStatus", "tags", "networkPresence", "books", 
"quotes",
+        "phoneNumbers", "languagesSpoken", "activities", "jobs", 
"dateOfBirth", "profileVideo",
+        "bodyType", "urls", "schools", "music", "addresses", 
"livingArrangement", "thumbnailUrl",
+        "humor", "sports", "scaredOf", "movies", "age", "pets", "hasApp", 
"turnOffs", "gender",
+        "fashion", "drinker", "aboutMe", "children", "sexualOrientation", 
"heroes", "profileSong",
+        "lookingFor", "cars", "turnOns", "tvShows", "profileUrl", "status", 
"currentLocation",
+        "smoker", "happiestWhen", "ethnicity", "food", "emails", 
"politicalViews", "interests",
+        "familyName", "honorificSuffix", "additionalName", "honorificPrefix", 
"givenName" };
 
     private String newfield;
 
@@ -145,21 +136,19 @@
 
     String result = beanJsonConverter.convertToString(cassie);
 
-    validatePerson(result, "5", "robot", SpecialPerson.OPTIONALFIELDS,
-        SpecialPerson.NULLFIELDS);
+    validatePerson(result, "5", "robot", SpecialPerson.OPTIONALFIELDS, 
SpecialPerson.NULLFIELDS);
 
     String[] optional = {};
     String[] nullfields = {};
-    Map<String, Object> special = apiValidator.validate(result,
-        new String[] { "newfield" }, optional, nullfields);
+    Map<String, Object> special = apiValidator.validate(result, new String[] { 
"newfield" },
+        optional, nullfields);
     assertNotNull(special.get("newfield"));
     assertEquals(String.class, special.get("newfield").getClass());
     assertEquals("nonsense", special.get("newfield"));
 
     // convert back into an object Tree
 
-    SpecialPerson parseCassie = beanJsonConverter.convertToObject(result,
-        SpecialPerson.class);
+    SpecialPerson parseCassie = beanJsonConverter.convertToObject(result, 
SpecialPerson.class);
 
     assertNotNull(parseCassie);
     assertEquals(cassie.getId(), parseCassie.getId());
@@ -181,18 +170,18 @@
    * @param result
    * @throws ApiValidatorExpcetion
    */
-  private void validatePerson(String result, String id, String name,
-      String[] optional, String[] nullfields) throws ApiValidatorExpcetion {
+  private void validatePerson(String result, String id, String name, String[] 
optional,
+      String[] nullfields) throws ApiValidatorExpcetion {
 
-    Map<String, Object> standard = apiValidator.validate(result, PERSON_FIELDS,
-        optional, nullfields);
+    Map<String, Object> standard = apiValidator.validate(result, 
PERSON_FIELDS, optional,
+        nullfields);
     assertNotNull(standard.get("id"));
     assertEquals(String.class, standard.get("id").getClass());
     assertEquals(id, standard.get("id"));
 
     assertNotNull(standard.get("name"));
-    Map<String, Object> nameJSON = apiValidator.validateObject(standard
-        .get("name"), NAME_FIELDS, optional, nullfields);
+    Map<String, Object> nameJSON = 
apiValidator.validateObject(standard.get("name"), NAME_FIELDS,
+        optional, nullfields);
     ApiValidator.dump(nameJSON);
 
     assertNotNull(nameJSON.get("unstructured"));
@@ -209,12 +198,10 @@
     if (outputInfo) {
       log.info("JSON (" + result + ")");
     }
-    Person parsedPerson = beanJsonConverter.convertToObject(result,
-        Person.class);
+    Person parsedPerson = beanJsonConverter.convertToObject(result, 
Person.class);
 
     assertEquals(johnDoe.getId(), parsedPerson.getId());
-    assertEquals(johnDoe.getName().getUnstructured(), parsedPerson.getName()
-        .getUnstructured());
+    assertEquals(johnDoe.getName().getUnstructured(), 
parsedPerson.getName().getUnstructured());
 
     List<Address> addresses = parsedPerson.getAddresses();
     if (outputInfo) {
@@ -228,8 +215,8 @@
     String unstructured = address.getUnstructuredAddress();
 
     assertNotNull(unstructured);
-    assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
-        parsedPerson.getAddresses().get(0).getUnstructuredAddress());
+    assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(), 
parsedPerson
+        .getAddresses().get(0).getUnstructuredAddress());
 
     assertEquals(3, parsedPerson.getPhoneNumbers().size());
 
@@ -256,8 +243,7 @@
     if (outputInfo) {
       log.info("JSON (" + result + ")");
     }
-    Activity parsedActivity = beanJsonConverter.convertToObject(result,
-        Activity.class);
+    Activity parsedActivity = beanJsonConverter.convertToObject(result, 
Activity.class);
     assertEquals(activity.getUserId(), parsedActivity.getUserId());
     assertEquals(activity.getId(), parsedActivity.getId());
 
@@ -268,8 +254,7 @@
 
     assertEquals(expectedItem.getUrl(), actualItem.getUrl());
     assertEquals(expectedItem.getMimeType(), actualItem.getMimeType());
-    assertEquals(expectedItem.getType().toString(), actualItem.getType()
-        .toString());
+    assertEquals(expectedItem.getType().toString(), 
actualItem.getType().toString());
   }
 
   public void testMapsToJson() throws Exception {
@@ -323,8 +308,7 @@
     if (outputInfo) {
       log.info("JSON (" + result + ")");
     }
-    Map<?, ?>[] parsedList = beanJsonConverter.convertToObject(result,
-        Map[].class);
+    Map<?, ?>[] parsedList = beanJsonConverter.convertToObject(result, 
Map[].class);
 
     assertEquals("1", parsedList[0].get("value"));
     assertEquals("2", parsedList[1].get("value"));
@@ -336,8 +320,7 @@
     if (outputInfo) {
       log.info("JSON (" + result + ")");
     }
-    String[] parsedColors = beanJsonConverter.convertToObject(result,
-        String[].class);
+    String[] parsedColors = beanJsonConverter.convertToObject(result, 
String[].class);
     assertEquals(colors.length, parsedColors.length);
     assertEquals(colors[0], parsedColors[0]);
     assertEquals(colors[1], parsedColors[1]);
@@ -347,8 +330,7 @@
   public void testJsonToActivity() throws Exception {
     String jsonActivity = "{userId : 5, id : 6, mediaItems : ["
         + "{url : 'hello', mimeType : 'mimey', type : 'VIDEO'}" + "]}";
-    Activity result = beanJsonConverter.convertToObject(jsonActivity,
-        Activity.class);
+    Activity result = beanJsonConverter.convertToObject(jsonActivity, 
Activity.class);
 
     assertEquals("5", result.getUserId());
     assertEquals("6", result.getId());
@@ -366,8 +348,8 @@
   public void testJsonToMap() throws Exception {
     String jsonActivity = "{count : 0, favoriteColor : 'yellow'}";
     Map<String, String> data = Maps.newHashMap();
-    data = beanJsonConverter.convertToObject(jsonActivity,
-        (Class<Map<String, String>>) data.getClass());
+    data = beanJsonConverter.convertToObject(jsonActivity, (Class<Map<String, 
String>>) data
+        .getClass());
 
     assertEquals(2, data.size());
 
@@ -381,4 +363,19 @@
     }
   }
 
+  public void testEmptyObject() {
+    assertEquals("{}", beanJsonConverter.convertToString(""));
+    assertEquals(0, beanJsonConverter.convertToObject("", Map.class).size());
+    assertEquals(0, beanJsonConverter.convertToObject("[]", 
String[].class).length);
+    assertEquals(2, beanJsonConverter.convertToObject("[\"a\",\"b\"]", 
String[].class).length);
+  }
+
+  public void testException() {
+    // a bit brain dead, but makes certain the exception is available in all 
forms
+    assertNotNull(new BeanJsonLibConversionException());
+    assertNotNull(new BeanJsonLibConversionException("message"));
+    assertNotNull(new BeanJsonLibConversionException(new Exception()));
+    assertNotNull(new BeanJsonLibConversionException("message", new 
Exception()));
+  }
+
 }

Added: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java?rev=679143&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java
 Wed Jul 23 10:47:52 2008
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.shindig.social.opensocial.util;
+
+import static org.junit.Assert.*;
+
+import org.apache.shindig.social.core.util.JsonLibConverterUtils;
+
+import com.sun.speech.freetts.Dumpable;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class JsonLibConverterUtilsTest {
+
+  /**
+   * Test method for
+   * [EMAIL PROTECTED] 
org.apache.shindig.social.core.util.JsonLibConverterUtils#dumpJsonObject(net.sf.json.JSONObject,
 java.lang.String)}.
+   */
+  @Test
+  public void testDumpJsonObject() {
+    JSONObject jo = new JSONObject();
+    JSONObject jo2 = new JSONObject();
+    jo.put("nested", jo2);
+    jo.put("array", new JSONArray());
+    jo.put("null", null);
+    jo.put("nonnull", "Non Null");
+    JsonLibConverterUtils.dumpJsonObject(jo, " ");
+  }
+
+  /**
+   * Test method for
+   * [EMAIL PROTECTED] 
org.apache.shindig.social.core.util.JsonLibConverterUtils#dumpJsonArray(net.sf.json.JSONArray,
 java.lang.String)}.
+   */
+  @Test
+  public void testDumpJsonArray() {
+    JSONObject jo = new JSONObject();
+    JSONObject jo2 = new JSONObject();
+    jo.put("nested", jo2);
+    jo.put("array", new JSONArray());
+    jo.put("null", null);
+    jo.put("nonnull", "Non Null");
+    JSONArray joa = new JSONArray();
+    JsonLibConverterUtils.dumpJsonArray(joa, " ");
+    joa.add(jo);
+    joa.add(jo);
+    JsonLibConverterUtils.dumpJsonArray(joa, " ");
+  }
+
+}

Added: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java?rev=679143&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java
 Wed Jul 23 10:47:52 2008
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.shindig.social.opensocial.util;
+
+import static org.junit.Assert.*;
+
+import org.apache.shindig.social.core.util.JsonObjectToMapMorpher;
+
+import net.sf.ezmorph.Morpher;
+import net.sf.ezmorph.ObjectMorpher;
+import net.sf.json.JSON;
+import net.sf.json.JSONObject;
+
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests the JsonObjectMapMorpher
+ */
+public class JsonObjectToMapMorpherTest {
+
+  /**
+   * Test method for
+   * [EMAIL PROTECTED] 
org.apache.shindig.social.core.util.JsonObjectToMapMorpher#morphsTo()}.
+   */
+  @Test
+  public void testMorphsTo() {
+    Morpher m = new JsonObjectToMapMorpher();
+    assertEquals(Map.class, m.morphsTo());
+  }
+
+  /**
+   * Test method for
+   * [EMAIL PROTECTED] 
org.apache.shindig.social.core.util.JsonObjectToMapMorpher#supports(java.lang.Class)}.
+   */
+  @Test
+  public void testSupports() {
+    Morpher m = new JsonObjectToMapMorpher();
+    assertTrue(m.supports(JSONObject.class));
+    assertFalse(m.supports(JSON.class));
+    assertFalse(m.supports(List.class));
+  }
+
+  /**
+   * Test method for
+   * [EMAIL PROTECTED] 
org.apache.shindig.social.core.util.JsonObjectToMapMorpher#morph(java.lang.Object)}.
+   */
+  @Test
+  public void testMorph() {
+    ObjectMorpher om = new JsonObjectToMapMorpher();
+    JSONObject testObj = new JSONObject();
+    testObj.put("x", "y");
+    testObj.put("1", "z");
+    Object o = om.morph(testObj);
+    assertNotSame(testObj, o);
+    if ( o instanceof Map ) {
+      Map<?, ?> fm = (Map<?, ?>) o;
+      assertEquals("y",fm.get("x"));
+      assertEquals("z",fm.get("1"));
+      assertNull(fm.get("xyz"));
+    }
+    try {
+      om.morph(o);
+      fail();
+    } catch ( ClassCastException cce ) {
+      assertTrue(true);
+    }
+  }
+
+}

Added: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java?rev=679143&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java
 Wed Jul 23 10:47:52 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.shindig.social.opensocial.util;
+
+import static org.junit.Assert.assertNull;
+import net.sf.json.processors.DefaultValueProcessor;
+
+import org.apache.shindig.social.core.util.NullDefaultValueProcessor;
+
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests the NullDefaultValueProcessor.
+ */
+public class NullDefaultValueProcessorTest {
+
+  /**
+   * Test method for
+   * [EMAIL PROTECTED] 
org.apache.shindig.social.core.util.NullDefaultValueProcessor#getDefaultValue(java.lang.Class)}.
+   */
+  @Test
+  public void testGetDefaultValue() {
+    DefaultValueProcessor defValue = new NullDefaultValueProcessor();
+    assertNull(defValue.getDefaultValue(String.class));
+    assertNull(defValue.getDefaultValue(List.class));
+    assertNull(defValue.getDefaultValue(Map.class));
+  }
+
+}

Added: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java?rev=679143&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java
 Wed Jul 23 10:47:52 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.shindig.social.opensocial.util;
+
+import net.sf.json.JSONArray;
+import net.sf.json.util.PropertyFilter;
+
+import org.apache.shindig.social.core.util.NullPropertyFilter;
+
+import com.google.common.collect.Lists;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+/**
+ * Test the NullPropertyFilter.
+ */
+public class NullPropertyFilterTest {
+  /**
+   * perform the test
+   */
+  @Test
+  public void testApply() {
+    PropertyFilter pf = new NullPropertyFilter();
+    Assert.assertTrue(pf.apply(null, null, null));
+    JSONArray jsa = new JSONArray();
+    Assert.assertTrue(pf.apply(null, null, jsa));
+    jsa.add("element");
+    Assert.assertFalse(pf.apply(null, null, jsa));
+    Assert.assertTrue(pf.apply(null, null, Lists.newArrayList()));
+    Assert.assertFalse(pf.apply(null, null, Lists.newArrayList("element", 
"element")));
+    Assert.assertTrue(pf.apply(null, null, new Object[] {}));
+    Assert.assertFalse(pf.apply(null, null, new Object[] { "element" }));
+  }
+}


Reply via email to