com.helger.commons.mock.CommonsTestHelper Java Examples

The following examples show how to use com.helger.commons.mock.CommonsTestHelper. 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: MimeTypeParameterTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  MimeTypeParameter p = new MimeTypeParameter ("charset", "iso-8859-1");
  assertEquals ("charset", p.getAttribute ());
  assertEquals ("iso-8859-1", p.getValue ());
  assertFalse (p.isValueRequiringQuoting ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (p,
                                                                     new MimeTypeParameter ("charset", "iso-8859-1"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (p,
                                                                         new MimeTypeParameter ("charsetname",
                                                                                                "iso-8859-1"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (p,
                                                                         new MimeTypeParameter ("charset", "utf-8"));

  p = new MimeTypeParameter ("charset", "foo bar");
  assertEquals ("charset", p.getAttribute ());
  assertEquals ("foo bar", p.getValue ());
  assertTrue (p.isValueRequiringQuoting ());
}
 
Example #2
Source File: HttpHeaderMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAllHeadersEmpty ()
{
  final HttpHeaderMap h = new HttpHeaderMap ();
  h.addHeader ("key1", "val1");
  h.addHeader ("key1", "val2");
  h.addHeader ("key1", "val3");

  final HttpHeaderMap h2 = new HttpHeaderMap ();
  h2.setAllHeaders (h);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (h2, h);

  CommonsTestHelper.testGetClone (h);
  CommonsTestHelper.testDefaultSerialization (h);
  CommonsTestHelper.testGetClone (h2);
  CommonsTestHelper.testDefaultSerialization (h2);
}
 
Example #3
Source File: StringIDFromGlobalPersistentLongIDFactoryTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  GlobalIDFactory.setPersistentLongIDFactory (new MemoryStaticLongIDFactory ());
  final StringIDFromGlobalPersistentLongIDFactory x = new StringIDFromGlobalPersistentLongIDFactory ("idd");
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (x,
                                                                     new StringIDFromGlobalPersistentLongIDFactory ("idd"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (x,
                                                                         new StringIDFromGlobalPersistentLongIDFactory ("prefix"));
  assertTrue (x.getNewID ().startsWith ("idd"));

  try
  {
    new StringIDFromGlobalPersistentLongIDFactory (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #4
Source File: SimpleGraphTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testCycles ()
{
  SimpleGraph sg = _buildGraph ();
  assertTrue (sg.isSelfContained ());

  sg = new SimpleGraph ();
  final IMutableGraphNode n1 = sg.createNode (null);
  final IMutableGraphNode n2 = sg.createNode (null);
  sg.createRelation (n1, n2);
  sg.createRelation (n2, n1);

  assertTrue (n1.hasRelations ());
  assertTrue (n1.isConnectedWith (n2));

  assertTrue (n2.hasRelations ());
  assertTrue (n2.isConnectedWith (n1));

  assertTrue (sg.isSelfContained ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (_buildGraph (), _buildGraph ());
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new SimpleGraph (), new SimpleGraph ());
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (_buildGraph (), new SimpleGraph ());
}
 
Example #5
Source File: HttpHeaderMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAllHeadersPrefilledSameName ()
{
  final HttpHeaderMap h = new HttpHeaderMap ();
  h.addHeader ("key1", "val1");
  h.addHeader ("key1", "val2");
  h.addHeader ("key1", "val3");

  final HttpHeaderMap h2 = new HttpHeaderMap ();
  h2.addIntHeader ("key1", 42);
  h2.addAllHeaders (h);
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (h2, h);

  assertEquals (4, h2.getAllHeaderLines (true).size ());
  assertEquals ("key1: 42", h2.getAllHeaderLines (true).get (0));
  assertEquals ("key1: val1", h2.getAllHeaderLines (true).get (1));
  assertEquals ("key1: val2", h2.getAllHeaderLines (true).get (2));
  assertEquals ("key1: val3", h2.getAllHeaderLines (true).get (3));

  CommonsTestHelper.testGetClone (h);
  CommonsTestHelper.testDefaultSerialization (h);
  CommonsTestHelper.testGetClone (h2);
  CommonsTestHelper.testDefaultSerialization (h2);
}
 
Example #6
Source File: StringIDFromGlobalPersistentIntIDFactoryTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  GlobalIDFactory.setPersistentIntIDFactory (new MemoryStaticIntIDFactory ());
  final StringIDFromGlobalPersistentIntIDFactory x = new StringIDFromGlobalPersistentIntIDFactory ("idd");
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (x,
                                                                     new StringIDFromGlobalPersistentIntIDFactory ("idd"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (x,
                                                                         new StringIDFromGlobalPersistentIntIDFactory ("prefix"));
  assertTrue (x.getNewID ().startsWith ("idd"));

  try
  {
    new StringIDFromGlobalPersistentIntIDFactory (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #7
Source File: CommonsHashSetTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ICommonsSet <String> aTest = new CommonsHashSet <> ();
  aTest.add ("aaa");
  aTest.add ("bbb");
  aTest.add ("ccc");

  final ICommonsList <String> aSortedKeys = aTest.getSorted (Comparator.naturalOrder ());
  assertEquals ("aaa", aSortedKeys.getAtIndex (0));
  assertEquals ("bbb", aSortedKeys.getAtIndex (1));
  assertEquals ("ccc", aSortedKeys.getAtIndex (2));

  CommonsTestHelper.testDefaultSerialization (aTest);
  CommonsTestHelper.testGetClone (aTest);
}
 
Example #8
Source File: CommonsLinkedHashSetTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ICommonsSet <String> aTest = new CommonsLinkedHashSet <> ();
  aTest.add ("aaa");
  aTest.add ("bbb");
  aTest.add ("ccc");

  final ICommonsList <String> aSortedKeys = aTest.getSorted (Comparator.naturalOrder ());
  assertEquals ("aaa", aSortedKeys.getAtIndex (0));
  assertEquals ("bbb", aSortedKeys.getAtIndex (1));
  assertEquals ("ccc", aSortedKeys.getAtIndex (2));

  CommonsTestHelper.testDefaultSerialization (aTest);
  CommonsTestHelper.testGetClone (aTest);
}
 
Example #9
Source File: DirectedGraphRelationTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet ()
{
  final DirectedGraphNode nf = new DirectedGraphNode ();
  final DirectedGraphNode nt = new DirectedGraphNode ();
  final DirectedGraphRelation gr = new DirectedGraphRelation (nf, nt);
  assertSame (gr.getFrom (), nf);
  assertSame (gr.getTo (), nt);

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new DirectedGraphRelation ("id1", nf, nt),
                                                                     new DirectedGraphRelation ("id1", nf, nt));
  // different IDs
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new DirectedGraphRelation (nf, nt),
                                                                         new DirectedGraphRelation (nf, nt));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new DirectedGraphRelation ("id1", nf, nt),
                                                                         new DirectedGraphRelation ("id1",
                                                                                                    nf,
                                                                                                    new DirectedGraphNode ()));
}
 
Example #10
Source File: ConfigurationSourcePropertiesTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ConfigurationSourceProperties c = new ConfigurationSourceProperties (f);
  assertSame (EConfigSourceType.RESOURCE, c.getSourceType ());
  assertEquals (EConfigSourceType.RESOURCE.getDefaultPriority (), c.getPriority ());
  assertTrue (c.isInitializedAndUsable ());
  assertSame (f, c.getResource ());
  assertEquals ("string", c.getConfigurationValue ("element1").getValue ());
  assertEquals ("2", c.getConfigurationValue ("element2").getValue ());
  assertNull (c.getConfigurationValue ("what a mess"));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (c, new ConfigurationSourceProperties (f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c, new ConfigurationSourceProperties (1234, f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c,
                                                                         new ConfigurationSourceProperties (new FileSystemResource (new File ("bla"))));
}
 
Example #11
Source File: FileSystemResourceTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccess ()
{
  FileSystemResource fr = new FileSystemResource ("pom.xml");
  assertTrue (fr.exists ());
  assertTrue (fr.getResourceID ().endsWith ("pom.xml"));
  assertTrue (fr.getPath ().endsWith ("pom.xml"));
  StreamHelper.close (fr.getReader (StandardCharsets.ISO_8859_1));
  final byte [] aBytes = StreamHelper.getAllBytes (fr);
  assertTrue (aBytes.length > 0);
  assertNotNull (fr.getAsURL ());
  assertNotNull (fr.getAsFile ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (fr, new FileSystemResource ("pom.xml"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (fr, fr.getReadableCloneForPath ("pom.xml"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (fr, fr.getWritableCloneForPath ("pom.xml"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (fr, new FileSystemResource ("pom.xml2"));

  fr = new FileSystemResource ("this file does not exist");
  assertFalse (fr.exists ());
  assertNull (fr.getInputStream ());
  assertNull (fr.getReader (StandardCharsets.ISO_8859_1));
}
 
Example #12
Source File: HttpHeaderMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAllHeadersPrefilledSameName ()
{
  final HttpHeaderMap h = new HttpHeaderMap ();
  h.addHeader ("key1", "val1");
  h.addHeader ("Key1", "val2");
  h.addHeader ("key1", "val3");

  final HttpHeaderMap h2 = new HttpHeaderMap ();
  h2.addIntHeader ("Key1", 42);
  h2.setAllHeaders (h);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (h2, h);

  assertEquals (3, h2.getAllHeaderLines (true).size ());
  assertEquals ("key1: val1", h2.getAllHeaderLines (true).get (0));
  assertEquals ("key1: val2", h2.getAllHeaderLines (true).get (1));
  assertEquals ("key1: val3", h2.getAllHeaderLines (true).get (2));

  CommonsTestHelper.testGetClone (h);
  CommonsTestHelper.testDefaultSerialization (h);
  CommonsTestHelper.testGetClone (h2);
  CommonsTestHelper.testDefaultSerialization (h2);
}
 
Example #13
Source File: CommonsLinkedHashMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ICommonsMap <String, String> aTest = new CommonsLinkedHashMap <> ();
  aTest.put ("aaa", "bla");
  aTest.put ("bbb", "blb");
  aTest.put ("ccc", "blc");

  final ICommonsOrderedSet <String> aSortedKeys = aTest.getSortedByKey (Comparator.naturalOrder ()).copyOfKeySet ();
  assertEquals ("aaa", aSortedKeys.getAtIndex (0));
  assertEquals ("bbb", aSortedKeys.getAtIndex (1));
  assertEquals ("ccc", aSortedKeys.getAtIndex (2));

  CommonsTestHelper.testDefaultSerialization (aTest);
  CommonsTestHelper.testGetClone (aTest);
}
 
Example #14
Source File: FilterIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testIteration5 ()
{
  // filtered elements at the beginning
  final List <String> aList = CollectionHelper.newList (null, null, "s1", "s2", "s3");
  final FilterIterator <String> it = new FilterIterator <> (aList, Objects::nonNull);
  assertNotNull (it);

  assertEquals ("s1", it.next ());
  assertEquals ("s2", it.next ());
  assertEquals ("s3", it.next ());

  CommonsTestHelper.testToStringImplementation (it);

  try
  {
    // can't call next if hasNext failed
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
}
 
Example #15
Source File: ClassPathResourceTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefault ()
{
  final ClassPathResource aCPISP1a = new ClassPathResource ("folder/test2.txt");
  final ClassPathResource aCPISP1b = new ClassPathResource ("folder/test2.txt");
  final ClassPathResource aCPISP2 = new ClassPathResource ("folder/test1.txt");
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aCPISP1a, aCPISP1b);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aCPISP1a,
                                                                     new ClassPathResource ("cp:folder/test2.txt"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aCPISP1a,
                                                                     new ClassPathResource ("classpath:folder/test2.txt"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aCPISP1a, aCPISP2);
  CommonsTestHelper.testDefaultSerialization (aCPISP1a);
  CommonsTestHelper.testDefaultSerialization (new ClassPathResource ("folder/test2.txt"));
  try
  {
    // Can't serialize with class loader
    CommonsTestHelper.testDefaultSerialization (new ClassPathResource ("folder/test2.txt",
                                                                       ClassLoaderHelper.getDefaultClassLoader ()));
    fail ();
  }
  catch (final IllegalArgumentException ex)
  {}
}
 
Example #16
Source File: CommonsConcurrentHashMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ICommonsMap <String, String> aTest = new CommonsConcurrentHashMap <> ();
  aTest.put ("aaa", "bla");
  aTest.put ("bbb", "blb");
  aTest.put ("ccc", "blc");

  final ICommonsSet <String> aSortedKeys = aTest.getSortedByKey (Comparator.naturalOrder ()).copyOfKeySet ();
  assertEquals ("aaa", aSortedKeys.getAtIndex (0));
  assertEquals ("bbb", aSortedKeys.getAtIndex (1));
  assertEquals ("ccc", aSortedKeys.getAtIndex (2));

  CommonsTestHelper.testDefaultSerialization (aTest);
  CommonsTestHelper.testGetClone (aTest);
}
 
Example #17
Source File: HttpHeaderMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAllHeadersEmpty ()
{
  final HttpHeaderMap h = new HttpHeaderMap ();
  h.addHeader ("key1", "val1");
  h.addHeader ("key1", "val2");
  h.addHeader ("key1", "val3");

  final HttpHeaderMap h2 = new HttpHeaderMap ();
  h2.addAllHeaders (h);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (h2, h);

  CommonsTestHelper.testGetClone (h);
  CommonsTestHelper.testDefaultSerialization (h);
  CommonsTestHelper.testGetClone (h2);
  CommonsTestHelper.testDefaultSerialization (h2);
}
 
Example #18
Source File: MicroEventTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final IMicroElement e1 = new MicroElement ("a1");
  final IMicroElement e2 = new MicroElement ("a1");
  MicroEvent e = new MicroEvent (EMicroEvent.NODE_INSERTED, e1, e2);
  assertEquals (EMicroEvent.NODE_INSERTED, e.getEventType ());
  assertSame (e1, e.getSourceNode ());
  assertSame (e2, e.getTargetNode ());
  CommonsTestHelper.testToStringImplementation (e);

  e = new MicroEvent (EMicroEvent.NODE_INSERTED, null, null);
  assertEquals (EMicroEvent.NODE_INSERTED, e.getEventType ());
  assertNull (e.getSourceNode ());
  assertNull (e.getTargetNode ());
  CommonsTestHelper.testToStringImplementation (e);
}
 
Example #19
Source File: ArrayIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testStdMethods ()
{
  final ArrayIterator <String> ae = new ArrayIterator <> (ArrayHelper.newArray ("Hallo",
                                                                                "Welt",
                                                                                "from",
                                                                                "Copenhagen"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (ae,
                                                                     new ArrayIterator <> (ArrayHelper.newArray ("Hallo",
                                                                                                                 "Welt",
                                                                                                                 "from",
                                                                                                                 "Copenhagen")));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (ae,
                                                                         new ArrayIterator <> (ArrayHelper.newArray ("Hallo",
                                                                                                                     "Welt",
                                                                                                                     "from")));
  ae.next ();
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (ae,
                                                                         new ArrayIterator <> (ArrayHelper.newArray ("Hallo",
                                                                                                                     "Welt",
                                                                                                                     "from",
                                                                                                                     "Copenhagen")));
}
 
Example #20
Source File: CommonsTreeMapTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final ICommonsMap <String, String> aTest = new CommonsTreeMap <> ();
  aTest.put ("aaa", "bla");
  aTest.put ("bbb", "blb");
  aTest.put ("ccc", "blc");

  final ICommonsOrderedSet <String> aSortedKeys = aTest.getSortedByKey (Comparator.naturalOrder ()).copyOfKeySet ();
  assertEquals ("aaa", aSortedKeys.getAtIndex (0));
  assertEquals ("bbb", aSortedKeys.getAtIndex (1));
  assertEquals ("ccc", aSortedKeys.getAtIndex (2));

  CommonsTestHelper.testDefaultSerialization (aTest);
  CommonsTestHelper.testGetClone (aTest);
}
 
Example #21
Source File: FileSystemByteStreamProviderTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  final FileSystemByteStreamProvider aFSSR = new FileSystemByteStreamProvider (new File ("."));
  final InputStream aIS = aFSSR.getInputStream ("pom.xml");
  assertNotNull (aIS);
  StreamHelper.close (aIS);

  final OutputStream aOS = aFSSR.getOutputStream ("$deleteme.txt", EAppend.DEFAULT);
  assertNotNull (aOS);
  StreamHelper.close (aOS);
  assertTrue (FileOperations.deleteFile (new File ("$deleteme.txt")).isSuccess ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FileSystemByteStreamProvider (new File (".")),
                                                                     new FileSystemByteStreamProvider (new File (".")));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FileSystemByteStreamProvider (new File (".")),
                                                                     new FileSystemByteStreamProvider ("."));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FileSystemByteStreamProvider (new File (".")),
                                                                         new FileSystemByteStreamProvider (new File ("..")));
}
 
Example #22
Source File: TypedObjectTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  final ObjectType ot1 = new ObjectType ("type1");
  final ObjectType ot2 = new ObjectType ("type2");
  final TypedObject <String> t1 = TypedObject.create (ot1, "id1");
  assertSame (ot1, t1.getObjectType ());
  assertEquals ("id1", t1.getID ());
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (t1, TypedObject.create (ot1, "id1"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (t1, TypedObject.create (t1));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (t1, TypedObject.create (ot1, "id2"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (t1, TypedObject.create (ot2, "id1"));

  // Serialization
  CommonsTestHelper.testDefaultSerialization (t1);
}
 
Example #23
Source File: StringIDFromGlobalLongIDFactoryTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  final StringIDFromGlobalLongIDFactory x = new StringIDFromGlobalLongIDFactory ("idd");
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (x, new StringIDFromGlobalLongIDFactory ("idd"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (x,
                                                                         new StringIDFromGlobalLongIDFactory ("prefix"));
  assertTrue (x.getNewID ().startsWith ("idd"));

  try
  {
    new StringIDFromGlobalLongIDFactory (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #24
Source File: JsonArrayTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialize ()
{
  final JsonArray aArray = new JsonArray ();
  CommonsTestHelper.testDefaultSerialization (aArray);
  aArray.add (5);
  CommonsTestHelper.testDefaultSerialization (aArray);
  aArray.add (3.1234);
  CommonsTestHelper.testDefaultSerialization (aArray);
  aArray.add ("This is a string");
  CommonsTestHelper.testDefaultSerialization (aArray);
  aArray.add (new JsonArray ().add ("nested").add (0).add (Double.valueOf (12.34)));
  CommonsTestHelper.testDefaultSerialization (aArray);
  aArray.add (new JsonObject ().add ("n1", "nested").add ("n2", 0).add ("n3", Double.valueOf (12.34)));
  CommonsTestHelper.testDefaultSerialization (aArray);
}
 
Example #25
Source File: HttpHeaderMapTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleValue ()
{
  final HttpHeaderMap h = new HttpHeaderMap ();
  h.addHeader ("key1", "val1");
  assertFalse (h.isEmpty ());
  assertTrue (h.isNotEmpty ());
  assertEquals (1, h.size ());
  assertNotNull (h.getAllHeaderLines (true));
  assertEquals (1, h.getAllHeaderLines (true).size ());
  assertEquals ("key1: val1", h.getAllHeaderLines (true).getFirst ());
  assertNotNull (h.getAllHeaderLines (false));
  assertEquals (1, h.getAllHeaderLines (false).size ());
  assertEquals ("key1: val1", h.getAllHeaderLines (false).getFirst ());
  assertNotNull (h.getAllHeaderNames ());
  assertEquals (1, h.getAllHeaderNames ().size ());
  assertEquals ("key1", h.getAllHeaderNames ().getFirst ());
  assertNotNull (h.getAllHeaders ());
  assertEquals (1, h.getAllHeaders ().size ());
  assertEquals ("key1", h.getAllHeaders ().getFirstKey ());
  assertNotNull (h.getAllHeaderValues ("key1"));
  assertEquals (1, h.getAllHeaderValues ("key1").size ());
  assertEquals ("val1", h.getAllHeaderValues ("key1").getFirst ());

  CommonsTestHelper.testGetClone (h);
  CommonsTestHelper.testDefaultSerialization (h);
}
 
Example #26
Source File: CSSURITest.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final CSSURI aURI = new CSSURI ("a.gif");
  assertEquals ("a.gif", aURI.getURI ());
  final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false);
  assertEquals ("url(a.gif)", aURI.getAsCSSString (aSettings));
  aSettings.setQuoteURLs (true);
  assertEquals ("url('a.gif')", aURI.getAsCSSString (aSettings));
  assertFalse (aURI.isDataURL ());
  assertNull (aURI.getAsDataURL ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aURI, new CSSURI ("a.gif"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aURI, new CSSURI ("b.gif"));
}
 
Example #27
Source File: WrappedReaderTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testAll () throws IOException
{
  final NonBlockingStringReader baos = new NonBlockingStringReader (StringHelper.getRepeated ('a', 100));
  try (final WrappedReader ws = new WrappedReader (baos))
  {
    assertTrue (ws.markSupported ());
    assertTrue (ws.ready ());
    ws.mark (0);
    ws.read ();
    assertEquals (4, ws.read (new char [4]));
    assertEquals (1, ws.read (new char [5], 1, 1));
    ws.read (CharBuffer.allocate (1));
    assertEquals (4, ws.skip (4));
    assertEquals (89, ws.skip (100));
    ws.reset ();
    assertEquals (100, ws.skip (100));
    CommonsTestHelper.testToStringImplementation (ws);
  }

  try (WrappedReader aReader = new WrappedReader (null))
  {
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #28
Source File: SuccessWithValueTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testAll ()
{
  SuccessWithValue <String> x = new SuccessWithValue <> (ESuccess.SUCCESS, "bla");
  assertTrue (x.isSuccess ());
  assertFalse (x.isFailure ());
  assertEquals ("bla", x.get ());
  assertEquals ("bla", x.getIfSuccess ("other"));
  assertEquals ("bla", x.getIfSuccessOrNull ());
  assertEquals ("other", x.getIfFailure ("other"));
  assertNull (x.getIfFailureOrNull ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (x, SuccessWithValue.createSuccess ("bla"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (x, SuccessWithValue.createFailure ("bla"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (x, SuccessWithValue.createSuccess ("Other"));

  x = new SuccessWithValue <> (ESuccess.SUCCESS, null);
  assertNull (x.get ());

  try
  {
    new SuccessWithValue <> (null, "bla");
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #29
Source File: FileSystemResourceProviderTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsAndHashcode ()
{
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FileSystemResourceProvider (),
                                                                     new FileSystemResourceProvider ());
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FileSystemResourceProvider ("src/test/resources"),
                                                                     new FileSystemResourceProvider ("src/test/resources"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FileSystemResourceProvider ("src/test/resources"),
                                                                     new FileSystemResourceProvider (new File ("src/test/resources")));
}
 
Example #30
Source File: CachingSAXInputSourceTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final IReadableResource aRes = new ClassPathResource ("xml/list.xml");

  CachingSAXInputSource is = new CachingSAXInputSource (aRes);
  assertEquals (aRes.getResourceID (), is.getSystemId ());
  assertNotNull (StreamHelper.getAllBytes (is.getByteStream ()));

  is = new CachingSAXInputSource ((IHasInputStream) aRes);
  assertNull (is.getSystemId ());
  assertNotNull (StreamHelper.getAllBytes (is.getByteStream ()));

  is = new CachingSAXInputSource (aRes, "sysid");
  assertEquals ("sysid", is.getSystemId ());
  assertNotNull (StreamHelper.getAllBytes (is.getByteStream ()));

  is = new CachingSAXInputSource (aRes.getInputStream ());
  assertNull (is.getSystemId ());
  assertNotNull (StreamHelper.getAllBytes (is.getByteStream ()));

  is = new CachingSAXInputSource (aRes.getInputStream (), "sysid");
  assertEquals ("sysid", is.getSystemId ());
  assertNotNull (StreamHelper.getAllBytes (is.getByteStream ()));

  CommonsTestHelper.testToStringImplementation (is);
}