com.helger.commons.collection.attr.StringMap Java Examples

The following examples show how to use com.helger.commons.collection.attr.StringMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EqualsHelperTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testMap ()
{
  final StringMap aMap = new StringMap ("a", "b").add ("c", "d");
  assertTrue (EqualsHelper.equalsCollection (aMap, aMap));
  assertTrue (EqualsHelper.equalsCollection (aMap, CollectionHelper.makeUnmodifiable (aMap)));
  assertTrue (EqualsHelper.equalsCollection (aMap, Collections.synchronizedMap (aMap)));
  assertTrue (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("c", "d")));
  assertTrue (EqualsHelper.equalsCollection (new CommonsHashMap <Integer, Integer> (), new CommonsHashMap <Double, Float> ()));

  assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsHashMap <Integer, Integer> ()));
  assertFalse (EqualsHelper.equalsCollection (new CommonsHashMap <Integer, Integer> (), aMap));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("A", "b").add ("c", "d")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "B").add ("c", "d")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("C", "d")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("c", "D")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new StringMap ("a", "b").add ("c", "d").add ("e", "f")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsArrayList <> ("a", "b", "c")));
  assertFalse (EqualsHelper.equalsCollection (aMap, new CommonsHashSet <> ("a", "b", "c")));
  assertFalse (EqualsHelper.equalsCollection (aMap, ArrayHelper.newArray ("a", "b", "c")));
}
 
Example #2
Source File: JsonObjectTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialize ()
{
  final JsonObject aObject = new JsonObject ();
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key1", true);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key2", (byte) 3);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key3", 'x');
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key4", 50);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key5", 51L);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key6", (short) 52);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key7", 3.1234);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key8", 3.1235f);
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add ("key9", "This is a string");
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.addJson ("key10", new JsonArray ().add ("nested").add (0).add (Double.valueOf (12.34)));
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.addJson ("key11", new JsonObject ().add ("n1", "nested").add ("n2", 0).add ("n3", Double.valueOf (12.34)));
  CommonsTestHelper.testDefaultSerialization (aObject);
  aObject.add (new MapEntry <> ("key12", "value12"));
  CommonsTestHelper.testDefaultSerialization (aObject);

  final JsonObject aObject2 = new JsonObject ();
  aObject2.addAll (aObject);
  CommonsTestHelper.testDefaultSerialization (aObject2);
  aObject2.addAll (new StringMap ().add ("a", "b").add ("c", "d"));
  CommonsTestHelper.testDefaultSerialization (aObject2);
  aObject2.addAllMapped (new StringMap ().add ("a", "b").add ("c", "d"), JsonValue::create);
  CommonsTestHelper.testDefaultSerialization (aObject2);
  aObject2.addAllMapped (new StringMap ().add ("e", "f").add ("g", "h"), Function.identity (), JsonValue::create);
  CommonsTestHelper.testDefaultSerialization (aObject2);
}
 
Example #3
Source File: EqualsHelperTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testEnumeration ()
{
  final ICommonsList <String> aCont = new CommonsArrayList <> ("a", "b", "c");
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont), IteratorHelper.getEnumeration (aCont)));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                             IteratorHelper.getEnumeration (CollectionHelper.makeUnmodifiable (aCont))));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                             IteratorHelper.getEnumeration (Collections.synchronizedList (aCont))));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                             IteratorHelper.getEnumeration (new CommonsArrayList <> (aCont))));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                             IteratorHelper.getEnumeration (new CommonsLinkedList <> (aCont))));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                             IteratorHelper.getEnumeration (new CommonsVector <> (aCont))));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                             IteratorHelper.getEnumeration (new NonBlockingStack <> (aCont))));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (new CommonsArrayList <String> ()),
                                             IteratorHelper.getEnumeration (new CommonsLinkedList <String> ())));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (new NonBlockingStack <String> ()),
                                             IteratorHelper.getEnumeration (new CommonsVector <String> ())));
  assertTrue (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (new NonBlockingStack <String> ()),
                                             IteratorHelper.getEnumeration (new Stack <String> ())));

  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsLinkedList <String> ())));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (new CommonsLinkedList <String> ()),
                                              IteratorHelper.getEnumeration (aCont)));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsArrayList <String> ())));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsArrayList <> ("a", "b"))));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsArrayList <> ("A", "b", "c"))));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsArrayList <> ("a", "B", "c"))));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsArrayList <> ("a", "b", "C"))));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new CommonsArrayList <> ("a", "b", "c", "d"))));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont),
                                              IteratorHelper.getEnumeration (new StringMap ("a", "b").add ("c", "d"))));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont), new CommonsHashSet <> ("a", "b", "c")));
  assertFalse (EqualsHelper.equalsCollection (IteratorHelper.getEnumeration (aCont), ArrayHelper.newArray ("a", "b", "c")));
}
 
Example #4
Source File: SimpleURLTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testCtor ()
{
  // only href
  SimpleURL aURL = new SimpleURL ();
  assertEquals ("", aURL.getAsStringWithEncodedParameters ());

  aURL = new SimpleURL ("");
  assertEquals ("", aURL.getAsStringWithEncodedParameters ());

  aURL = new SimpleURL ("#");
  assertEquals ("", aURL.getAsStringWithEncodedParameters ());

  aURL = new SimpleURL ("?");
  assertEquals ("", aURL.getAsStringWithEncodedParameters ());

  aURL = new SimpleURL ("?#");
  assertEquals ("", aURL.getAsStringWithEncodedParameters ());

  aURL = new SimpleURL ("  ?  #  ");
  assertEquals ("", aURL.getAsStringWithEncodedParameters ());

  aURL = new SimpleURL ("http://www.helger.com");
  assertEquals ("http://www.helger.com", aURL.getAsStringWithEncodedParameters ());

  // params
  // 1. default
  aURL = new SimpleURL ("http://www.helger.com", new StringMap ("a", "b"));
  assertEquals ("http://www.helger.com?a=b", aURL.getAsStringWithEncodedParameters ());
  // 2. plus params in href
  aURL = new SimpleURL ("http://www.helger.com?x=y", new StringMap ("a", "b"));
  assertEquals ("http://www.helger.com?x=y&a=b", aURL.getAsStringWithEncodedParameters ());
  // 3. add parameter with same name in href
  aURL = new SimpleURL ("http://www.helger.com?a=a", new StringMap ("a", "b"));
  assertEquals ("http://www.helger.com?a=a&a=b", aURL.getAsStringWithEncodedParameters ());
  // 4. only params
  aURL = new SimpleURL ("", new StringMap ("a", "b"));
  assertEquals ("?a=b", aURL.getAsStringWithEncodedParameters ());
  // 4a. only params
  aURL = new SimpleURL ("?", new StringMap ("a", "b"));
  assertEquals ("?a=b", aURL.getAsStringWithEncodedParameters ());
  // 4b. only params
  aURL = new SimpleURL ("#", new StringMap ("a", "b"));
  assertEquals ("?a=b", aURL.getAsStringWithEncodedParameters ());
  assertEquals ("?a=b", aURL.getAsStringWithEncodedParameters ());
  // 4c. only params
  aURL = new SimpleURL ("#", new StringMap ().add ("a", null));
  assertEquals ("?a", aURL.getAsStringWithEncodedParameters ());
  // 4d. only params
  aURL = new SimpleURL ("#", new StringMap ().add ("a", ""));
  assertEquals ("?a", aURL.getAsStringWithEncodedParameters ());
  // 4e. only params
  aURL = new SimpleURL ("#").add ("a");
  assertEquals ("?a", aURL.getAsStringWithEncodedParameters ());
  // 4f. only params
  aURL = new SimpleURL ("#").add ("a", (String) null);
  assertEquals ("?a", aURL.getAsStringWithEncodedParameters ());

  // anchor
  // 1. default
  aURL = new SimpleURL ("http://www.helger.com", new StringMap ("a", "b"), "root");
  assertEquals ("http://www.helger.com?a=b#root", aURL.getAsStringWithEncodedParameters ());
  // 2. overwrite anchor
  aURL = new SimpleURL ("http://www.helger.com#main", new StringMap ("a", "b"), "root");
  assertEquals ("http://www.helger.com?a=b#root", aURL.getAsStringWithEncodedParameters ());
  // 3. only anchor in href
  aURL = new SimpleURL ("http://www.helger.com#main", new StringMap ("a", "b"));
  assertEquals ("http://www.helger.com?a=b#main", aURL.getAsStringWithEncodedParameters ());
  // 4. only params and anchor
  aURL = new SimpleURL ("#main", new StringMap ("a", "b"));
  assertEquals ("?a=b#main", aURL.getAsStringWithEncodedParameters ());
  // 5. only anchor
  aURL = new SimpleURL ("#main");
  assertEquals ("#main", aURL.getAsStringWithEncodedParameters ());
  // 5a. only anchor
  aURL = new SimpleURL ("", (Map <String, String>) null, "main");
  assertEquals ("#main", aURL.getAsStringWithEncodedParameters ());
  // 5b. only anchor
  aURL = new SimpleURL ("", (List <URLParameter>) null, "main");
  assertEquals ("#main", aURL.getAsStringWithEncodedParameters ());

  // Copy ctor
  final ISimpleURL aURL2 = new SimpleURL (aURL);
  assertEquals (aURL, aURL2);

  CommonsTestHelper.testGetClone (aURL);
}
 
Example #5
Source File: CSSURLHelperTest.java    From ph-css with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetAsCSSURL ()
{
  for (final String sURL : new String [] { "a.gif",
                                           "\"a.gif\"",
                                           "b\\a.gif",
                                           "\\b\\a\\c.gif",
                                           "'a.gif'",
                                           "'a\".gif'",
                                           "\"a'.gif\"",
                                           "a().gif",
                                           "a\\(\\).gif" })
  {
    final String sEscaped = CSSURLHelper.getAsCSSURL (sURL, false);
    assertEquals (sURL, CSSParseHelper.trimUrl (sEscaped));
  }

  assertEquals ("url(a.gif)", CSSURLHelper.getAsCSSURL ("a.gif", false));
  // By default: single quotes
  assertEquals ("url('a.gif')", CSSURLHelper.getAsCSSURL ("a.gif", true));
  // Force single quotes
  assertEquals ("url('\"a.gif\"')", CSSURLHelper.getAsCSSURL ("\"a.gif\"", true));
  // auto-quote
  assertEquals ("url('\"a.gif\"')", CSSURLHelper.getAsCSSURL ("\"a.gif\"", false));
  // auto-quote
  assertEquals ("url('b\\\\a.gif')", CSSURLHelper.getAsCSSURL ("b\\a.gif", false));
  // Force double quotes
  assertEquals ("url(\"'a.gif'\")", CSSURLHelper.getAsCSSURL ("'a.gif'", true));
  // auto-quote
  assertEquals ("url(\"'a.gif'\")", CSSURLHelper.getAsCSSURL ("'a.gif'", false));
  // Containing char to be escaped
  assertEquals ("url('\\'a\".gif\\'')", CSSURLHelper.getAsCSSURL ("'a\".gif'", true));
  // auto-quote
  assertEquals ("url('\\'a\".gif\\'')", CSSURLHelper.getAsCSSURL ("'a\".gif'", false));
  // Containing char to be escaped
  assertEquals ("url('\"a\\'.gif\"')", CSSURLHelper.getAsCSSURL ("\"a'.gif\"", true));
  // auto-quote
  assertEquals ("url('\"a\\'.gif\"')", CSSURLHelper.getAsCSSURL ("\"a'.gif\"", false));
  // Escaped brackets
  assertEquals ("url('a().gif')", CSSURLHelper.getAsCSSURL ("a().gif", false));

  final SimpleURL aURL = new SimpleURL ("a.gif", new StringMap ("x", "y"));
  assertEquals ("url(a.gif?x=y)", CSSURLHelper.getAsCSSURL (aURL, false));
  assertEquals ("url('a.gif?x=y')", CSSURLHelper.getAsCSSURL (aURL, true));
  assertEquals ("url()", CSSURLHelper.getAsCSSURL (new SimpleURL (), false));
  assertEquals ("url('')", CSSURLHelper.getAsCSSURL (new SimpleURL (), true));

  // SimpleURL -> CSS URL -> String -> SimpleURL
  assertEquals (aURL, new SimpleURL (CSSURLHelper.getURLValue (CSSURLHelper.getAsCSSURL (aURL, true))));

  // empty URL!
  assertEquals ("url()", CSSURLHelper.getAsCSSURL ("", false));
  assertEquals ("url('')", CSSURLHelper.getAsCSSURL ("", true));
}