Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2006-2014 phloc systems http://www.phloc.com office[at]phloc[dot]com 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.
package com.phloc.json;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public final class JSONComplexUtilsTest
  private static final String PROP1 = "Property1"//$NON-NLS-1$
  private static final String PROP2 = "Property2"//$NON-NLS-1$
  private static final String PROP3 = "Property3"//$NON-NLS-1$
  private static final String PROP4 = "Property4"//$NON-NLS-1$
  private static final String PROP5 = "Property5"//$NON-NLS-1$
  private static final String VALUE_STRING = "VALUE"//$NON-NLS-1$
  private static final Integer VALUE_INTEGER = Integer.valueOf (42);
  private static final Double VALUE_DOUBLE = Double.valueOf (3.2);
  private static final Boolean VALUE_BOOLEAN = .;
  @SuppressWarnings ("static-method")
  @Test
  public void testConvertToJSON ()
  {
    // test empty (null) property map
    {
      final IJSONObject aObj = JSONComplexUtils.convertToJSON (null);
      assertNotNull (aObj);
      assertEquals (aObj.getAllPropertyNames ().size (), 0);
    }
    // test mixed types
    {
      final Map <StringObjectaProperties = new HashMap <StringObject> ();
      aProperties.put ();
      aProperties.put ();
      aProperties.put ();
      aProperties.put ();
      aProperties.put (null);
      final IJSONObject aObj = JSONComplexUtils.convertToJSON (aProperties);
      assertNotNull (aObj);
      assertEquals (aObj.getAllPropertyNames ().size (), aProperties.size ());
      assertEquals (aObj.getProperty ().getValue ().getData (), );
      assertEquals (aObj.getProperty ().getValue ().getData (), );
      assertEquals (aObj.getProperty ().getValue ().getData (), );
      assertEquals (aObj.getProperty ().getValue ().getData (), );
      assertTrue (aObj.getProperty ().getValue () instanceof JSONPropertyValueKeyword);
    }
  }
New to GrepCode? Check out our FAQ X