Java Code Examples for com.helger.commons.mock.CommonsTestHelper#testDefaultImplementationWithDifferentContentObject()

The following examples show how to use com.helger.commons.mock.CommonsTestHelper#testDefaultImplementationWithDifferentContentObject() . 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: SingleElementEnumerationTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAll ()
{
  final SingleElementEnumeration <String> eit = new SingleElementEnumeration <> ("any");
  assertTrue (eit.hasMoreElements ());

  assertEquals ("any", eit.nextElement ());
  try
  {
    eit.nextElement ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
  assertFalse (eit.hasMoreElements ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new SingleElementEnumeration <> ("any"),
                                                                     new SingleElementEnumeration <> ("any"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new SingleElementEnumeration <> ("any"),
                                                                         new SingleElementEnumeration <> ("any2"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new SingleElementEnumeration <> ("any"),
                                                                         new SingleElementEnumeration <> (Integer.valueOf (1)));
}
 
Example 2
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 3
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 4
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 5
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 6
Source File: GraphRelationTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet ()
{
  final GraphNode nf = new GraphNode ();
  final GraphNode nt = new GraphNode ();
  final GraphRelation gr = new GraphRelation (nf, nt);
  assertEquals (2, gr.getAllConnectedNodes ().size ());
  assertTrue (gr.getAllConnectedNodes ().contains (nf));
  assertTrue (gr.getAllConnectedNodes ().contains (nt));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new GraphRelation ("id1", nf, nt),
                                                                     new GraphRelation ("id1", nf, nt));
  // different IDs
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new GraphRelation (nf, nt),
                                                                         new GraphRelation (nf, nt));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new GraphRelation ("id1", nf, nt),
                                                                         new GraphRelation ("id1",
                                                                                            nf,
                                                                                            new GraphNode ()));
}
 
Example 7
Source File: MutableBooleanTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testMutableBoolean ()
{
  final MutableBoolean x = new MutableBoolean (false);
  assertFalse (x.booleanValue ());
  assertSame (Boolean.FALSE, x.getAsBoolean ());
  assertTrue (x.set (true).isChanged ());
  assertTrue (x.booleanValue ());
  assertSame (Boolean.TRUE, x.getAsBoolean ());
  assertFalse (x.set (true).isChanged ());
  assertTrue (x.booleanValue ());
  assertSame (Boolean.TRUE, x.getAsBoolean ());
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new MutableBoolean (true),
                                                                     new MutableBoolean (true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new MutableBoolean (true),
                                                                         new MutableBoolean (false));
  CommonsTestHelper.testGetClone (new MutableBoolean (true));
}
 
Example 8
Source File: DefaultTreeItemWithIDTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testStdMethods ()
{
  final DefaultTreeWithID <String, String> t = new DefaultTreeWithID <> ();
  final DefaultTreeWithID <String, String> t2 = new DefaultTreeWithID <> ();
  t2.getRootItem ().createChildItem ("dataid", "Data");

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (t.getRootItem (),
                                                                     new DefaultTreeWithID <String, String> ().getRootItem ());
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (t.getRootItem (), t2.getRootItem ());
}
 
Example 9
Source File: LSResourceDataTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault ()
{
  final LSResourceData rd = new LSResourceData ("http://www.w3.org/2001/XMLSchema",
                                                "http://www.example.org/schema1",
                                                null,
                                                "schema1.xsd",
                                                "my/path/xml/schema2.xsd");
  assertEquals ("http://www.w3.org/2001/XMLSchema", rd.getType ());
  assertEquals ("http://www.example.org/schema1", rd.getNamespaceURI ());
  assertNull (rd.getPublicID ());
  assertEquals ("schema1.xsd", rd.getSystemID ());
  assertNotNull (rd.getBaseURI ());
  assertTrue (rd.getBaseURI ().endsWith ("xml/schema2.xsd"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (rd,
                                                                         new LSResourceData (null,
                                                                                             null,
                                                                                             null,
                                                                                             null,
                                                                                             null));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (rd,
                                                                     new LSResourceData (rd.getType (),
                                                                                         rd.getNamespaceURI (),
                                                                                         rd.getPublicID (),
                                                                                         rd.getSystemID (),
                                                                                         rd.getBaseURI ()));
}
 
Example 10
Source File: TimeValueTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testAll ()
{
  final TimeValue t = new TimeValue (TimeUnit.SECONDS, 5);
  assertEquals (TimeUnit.SECONDS, t.getTimeUnit ());
  assertEquals (5, t.getDuration ());
  assertEquals (0, t.getAsDays ());
  assertEquals (0, t.getAsHours ());
  assertEquals (0, t.getAsMinutes ());
  assertEquals (5, t.getAsSeconds ());
  assertEquals (5000, t.getAsMillis ());
  assertEquals (5000000, t.getAsMicros ());
  assertEquals (5000000000L, t.getAsNanos ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new TimeValue (TimeUnit.SECONDS, 5),
                                                                     new TimeValue (TimeUnit.SECONDS, 5));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new TimeValue (TimeUnit.SECONDS, 5),
                                                                         new TimeValue (TimeUnit.SECONDS, 4));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new TimeValue (TimeUnit.SECONDS, 5),
                                                                         new TimeValue (TimeUnit.NANOSECONDS, 5));
  try
  {
    new TimeValue (null, 5);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example 11
Source File: ConfigurationSourceJsonTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final ConfigurationSourceJson c = new ConfigurationSourceJson (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 ());
  assertEquals ("1234", c.getConfigurationValue ("element5.network.port").getValue ());
  assertNull (c.getConfigurationValue ("what a mess"));

  // Check array
  assertEquals ("4", c.getConfigurationValue ("element6.$count").getValue ());
  assertEquals ("17", c.getConfigurationValue ("element6.0").getValue ());
  assertEquals ("12", c.getConfigurationValue ("element6.3").getValue ());

  assertEquals ("3", c.getConfigurationValue ("element7.$count").getValue ());
  assertEquals ("10", c.getConfigurationValue ("element7.0.key").getValue ());
  assertNull (c.getConfigurationValue ("element7.0.value"));
  assertEquals ("3", c.getConfigurationValue ("element7.0.value.$count").getValue ());
  assertEquals ("bar", c.getConfigurationValue ("element7.0.value.2").getValue ());
  assertEquals ("plain value", c.getConfigurationValue ("element7.1").getValue ());
  assertEquals ("blub", c.getConfigurationValue ("element7.2.value.0").getValue ());
  // Check additional
  assertEquals ("value", c.getConfigurationValue ("element7.sub.key").getValue ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (c, new ConfigurationSourceJson (f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c, new ConfigurationSourceJson (1234, f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c,
                                                                         new ConfigurationSourceJson (new FileSystemResource (new File ("bla"))));
}
 
Example 12
Source File: CSSHSLTest.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false);
  final CSSHSL aColor = new CSSHSL (1, 2, 3);
  assertEquals ("hsl(1,2%,3%)", aColor.getAsCSSString (aSettings));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aColor, new CSSHSL (aColor));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aColor, new CSSHSL (1, 2, 3));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSHSL (0, 2, 3));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSHSL (1, 0, 3));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSHSL (1, 2, 0));
}
 
Example 13
Source File: ConfigurationSourceSystemPropertyTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final ConfigurationSourceSystemProperty c = new ConfigurationSourceSystemProperty ();
  assertSame (EConfigSourceType.SYSTEM_PROPERTY, c.getSourceType ());
  assertEquals (EConfigSourceType.SYSTEM_PROPERTY.getDefaultPriority (), c.getPriority ());
  assertTrue (c.isInitializedAndUsable ());
  assertNotNull (c.getConfigurationValue (SystemProperties.SYSTEM_PROPERTY_JAVA_HOME));
  assertNull (c.getConfigurationValue ("I really don't know that system property!"));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (c, new ConfigurationSourceSystemProperty ());
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (c,
                                                                         new ConfigurationSourceSystemProperty (1234));
}
 
Example 14
Source File: ClassPathResourceProviderTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsAndHashcode ()
{
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new ClassPathResourceProvider (),
                                                                     new ClassPathResourceProvider ());
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new ClassPathResourceProvider (),
                                                                         new ClassPathResourceProvider ("folder"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new ClassPathResourceProvider ("folder"),
                                                                     new ClassPathResourceProvider ("folder"));
}
 
Example 15
Source File: FactoryNewInstanceTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsAndHashCode ()
{
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (FactoryNewInstance.create (String.class),
                                                                     FactoryNewInstance.create (String.class));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (FactoryNewInstance.create (String.class),
                                                                         FactoryNewInstance.create (StringBuilder.class));
}
 
Example 16
Source File: CSSRGBATest.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false);
  final CSSRGBA aColor = new CSSRGBA (1, 2, 3, 0.5f);
  assertEquals ("rgba(1,2,3,0.5)", aColor.getAsCSSString (aSettings));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aColor, new CSSRGBA (aColor));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aColor, new CSSRGBA (1, 2, 3, 0.5f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGBA (0, 2, 3, 0.5f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGBA (1, 0, 3, 0.5f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGBA (1, 2, 0, 0.5f));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGBA (1, 2, 3, 0f));
}
 
Example 17
Source File: FormatableObjectTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testImpl ()
{
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FormatableObject <> ("Any",
                                                                                              FormatterStringPrefixAndSuffix.createWithBrackets ()),
                                                                     new FormatableObject <> ("Any",
                                                                                              FormatterStringPrefixAndSuffix.createWithBrackets ()));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatableObject <> ("Any",
                                                                                                  FormatterStringPrefixAndSuffix.createWithBrackets ()),
                                                                         new FormatableObject <> ("Any2",
                                                                                                  FormatterStringPrefixAndSuffix.createWithBrackets ()));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatableObject <> ("Any",
                                                                                                  FormatterStringPrefixAndSuffix.createWithBrackets ()),
                                                                         new FormatableObject <> ("Any",
                                                                                                  FormatterStringPrefixAndSuffix.createPrefixOnly ("oprefix")));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (FormatterStringPrefixAndSuffix.createWithBrackets (),
                                                                     FormatterStringPrefixAndSuffix.createWithBrackets ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FormatterMinLengthAddLeading (10, ' '),
                                                                     new FormatterMinLengthAddLeading (10, ' '));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatterMinLengthAddLeading (10, ' '),
                                                                         new FormatterMinLengthAddLeading (10, 'x'));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatterMinLengthAddLeading (10, ' '),
                                                                         new FormatterMinLengthAddLeading (5, ' '));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FormatterMinLengthAddTrailing (10, ' '),
                                                                     new FormatterMinLengthAddTrailing (10, ' '));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatterMinLengthAddTrailing (10, ' '),
                                                                         new FormatterMinLengthAddTrailing (10, 'x'));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatterMinLengthAddTrailing (10, ' '),
                                                                         new FormatterMinLengthAddTrailing (5, ' '));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new FormatterStringPrefixAndSuffix ("p", "s"),
                                                                     new FormatterStringPrefixAndSuffix ("p", "s"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatterStringPrefixAndSuffix ("p",
                                                                                                             "s"),
                                                                         new FormatterStringPrefixAndSuffix ("p",
                                                                                                             "ss"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new FormatterStringPrefixAndSuffix ("p",
                                                                                                             "s"),
                                                                         new FormatterStringPrefixAndSuffix ("pp",
                                                                                                             "s"));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (FormatterStringPrefixAndSuffix.createPrefixOnly ("p"),
                                                                     FormatterStringPrefixAndSuffix.createPrefixOnly ("p"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (FormatterStringPrefixAndSuffix.createPrefixOnly ("p"),
                                                                         FormatterStringPrefixAndSuffix.createPrefixOnly ("pp"));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (FormatterStringPrefixAndSuffix.createSuffixOnly ("s"),
                                                                     FormatterStringPrefixAndSuffix.createSuffixOnly ("s"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (FormatterStringPrefixAndSuffix.createSuffixOnly ("s"),
                                                                         FormatterStringPrefixAndSuffix.createSuffixOnly ("ss"));
}
 
Example 18
Source File: ThirdPartyModuleTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testStd ()
{
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new ThirdPartyModule ("displayname",
                                                                                           "owner",
                                                                                           ELicense.APACHE1),
                                                                     new ThirdPartyModule ("displayname",
                                                                                           "owner",
                                                                                           ELicense.APACHE1));
  final ThirdPartyModule mod = new ThirdPartyModule ("displayname",
                                                     "owner",
                                                     ELicense.APACHE1,
                                                     Version.parse ("1.1"),
                                                     "url",
                                                     true);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (mod,
                                                                     new ThirdPartyModule ("displayname",
                                                                                           "owner",
                                                                                           ELicense.APACHE1,
                                                                                           Version.parse ("1.1"),
                                                                                           "url",
                                                                                           true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (mod,
                                                                         new ThirdPartyModule ("displayname2",
                                                                                               "owner",
                                                                                               ELicense.APACHE1,
                                                                                               Version.parse ("1.1"),
                                                                                               "url",
                                                                                               true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (mod,
                                                                         new ThirdPartyModule ("displayname",
                                                                                               "owner2",
                                                                                               ELicense.APACHE1,
                                                                                               Version.parse ("1.1"),
                                                                                               "url",
                                                                                               true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (mod,
                                                                         new ThirdPartyModule ("displayname",
                                                                                               "owner",
                                                                                               ELicense.APACHE2,
                                                                                               Version.parse ("1.1"),
                                                                                               "url",
                                                                                               true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (mod,
                                                                         new ThirdPartyModule ("displayname",
                                                                                               "owner",
                                                                                               ELicense.APACHE1,
                                                                                               Version.parse ("1.1.2"),
                                                                                               "url",
                                                                                               true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (mod,
                                                                         new ThirdPartyModule ("displayname",
                                                                                               "owner",
                                                                                               ELicense.APACHE1,
                                                                                               Version.parse ("1.1"),
                                                                                               "url2",
                                                                                               true));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (mod,
                                                                         new ThirdPartyModule ("displayname",
                                                                                               "owner",
                                                                                               ELicense.APACHE1,
                                                                                               Version.parse ("1.1"),
                                                                                               "url",
                                                                                               false));
}
 
Example 19
Source File: AttributeContainerAnyTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testInit ()
{
  final AttributeContainerAny <String> x = new AttributeContainerAny <> ();
  assertNotNull (x.keySet ());
  assertTrue (x.keySet ().isEmpty ());
  assertTrue (x.isEmpty ());
  assertTrue (x.putIn ("key", "value").isChanged ());
  assertFalse (x.isEmpty ());
  assertEquals (1, x.size ());
  assertTrue (x.putIn ("key2", "value2").isChanged ());
  assertTrue (x.putIn ("key", "value3").isChanged ());
  assertFalse (x.putIn ("key", "value3").isChanged ());
  assertEquals ("value2", x.getValue ("key2"));
  assertEquals ("value2", x.getAsString ("key2"));
  assertEquals ("value2", x.<String> getCastedValue ("key2"));
  assertEquals ("value2", x.getCastedValue ("key2", String.class));
  try
  {
    x.getCastedValue ("key2", Integer.class);
    fail ();
  }
  catch (final ClassCastException ex)
  {}
  assertEquals ("value2", x.getSafeCastedValue ("key2", String.class));
  assertNull (x.getSafeCastedValue ("key2", Integer.class));
  assertEquals ("value2", x.getConvertedValue ("key2", String.class));
  assertEquals ("def", x.<String> getCastedValue ("key none", "def"));
  assertEquals (Integer.valueOf (5), x.getSafeCastedValue ("key2", Integer.valueOf (5), Integer.class));
  assertEquals ("def", x.getConvertedValue ("key none", "def", String.class));
  assertTrue (x.containsKey ("key2"));
  assertTrue (x.removeAll ().isChanged ());
  assertFalse (x.removeAll ().isChanged ());
  assertFalse (x.containsKey ("key2"));
  assertTrue (x.isEmpty ());
  assertTrue (x.keySet ().isEmpty ());
  assertFalse (x.removeObject ("key2").isChanged ());

  assertTrue (x.putIn ("key", Integer.valueOf (17)).isChanged ());
  assertTrue (x.getAsBoolean ("key"));
  assertEquals (17, x.getAsInt ("key"));
  assertEquals (17, x.getAsLong ("key"));
  assertEquals (CGlobal.ILLEGAL_UINT, x.getAsInt ("key2"));
  assertEquals (Integer.valueOf (17), x.getCastedValue ("key"));
  CommonsAssert.assertEquals (17, x.getAsDouble ("key"));
  CommonsAssert.assertEquals (CGlobal.ILLEGAL_DOUBLE, x.getAsDouble ("key2"));
  assertEquals (new BigInteger ("17"), x.getAsBigInteger ("key"));
  assertEquals (new BigDecimal ("17"), x.getAsBigDecimal ("key"));
  assertFalse (x.getAsBoolean ("key2"));
  assertTrue (x.removeObject ("key").isChanged ());
  assertFalse (x.removeObject ("key").isChanged ());

  // Check null values
  assertTrue (x.putIn ("null1", null).isUnchanged ());
  assertNull (x.getValue ("null1"));
  assertTrue (x.containsKey ("null1"));
  assertTrue (x.removeObject ("null1").isUnchanged ());
  assertNull (x.getValue ("null1"));
  assertFalse (x.containsKey ("null1"));
  assertTrue (x.removeObject ("null1").isUnchanged ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new AttributeContainerAny <String> (),
                                                                     new AttributeContainerAny <String> ());
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new AttributeContainerAny <> (CollectionHelper.newMap (new String [] { "key",
                                                                                                                                            "key2" },
                                                                                                                            new Object [] { "value",
                                                                                                                                            "value2" })),
                                                                     new AttributeContainerAny <> (CollectionHelper.newMap (new String [] { "key",
                                                                                                                                            "key2" },
                                                                                                                            new Object [] { "value",
                                                                                                                                            "value2" })));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new AttributeContainerAny <> (CollectionHelper.newMap (new String [] { "key",
                                                                                                                                                "key2" },
                                                                                                                                new Object [] { "value",
                                                                                                                                                "value2" })),
                                                                         new AttributeContainerAny <> (CollectionHelper.newMap (new String [] { "key",
                                                                                                                                                "key2" },
                                                                                                                                new Object [] { "value",
                                                                                                                                                "value" })));

  assertTrue (new AttributeContainerAny <> ((Map <String, Object>) null).isEmpty ());
}
 
Example 20
Source File: LRUSetTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Test
public void testLRUCache ()
{
  final LRUSet <Integer> aCache = new LRUSet <> (MAX_SIZE);
  assertTrue (aCache.isEmpty ());
  assertEquals (0, aCache.size ());
  assertEquals (MAX_SIZE, aCache.getMaxSize ());
  assertNotNull (aCache.iterator ());
  assertFalse (aCache.iterator ().hasNext ());

  for (int i = 0; i < MAX_SIZE * 2; ++i)
  {
    assertEquals (i < MAX_SIZE ? i : MAX_SIZE, aCache.size ());
    assertTrue (aCache.add (Integer.valueOf (i)));
  }
  assertEquals (MAX_SIZE, aCache.size ());

  // add the same again
  assertTrue (aCache.add (Integer.valueOf (-3)));
  assertFalse (aCache.add (Integer.valueOf (-3)));
  assertEquals (MAX_SIZE, aCache.size ());

  // addAll
  assertTrue (aCache.addAll (PrimitiveCollectionHelper.newPrimitiveList (-4, -5)));
  assertTrue (aCache.addAll (PrimitiveCollectionHelper.newPrimitiveList (-4, -6)));
  assertEquals (MAX_SIZE, aCache.size ());

  // containsAll
  assertTrue (aCache.containsAll (PrimitiveCollectionHelper.newPrimitiveList (-4, -5)));
  assertFalse (aCache.containsAll (PrimitiveCollectionHelper.newPrimitiveList (-4, -7)));
  assertEquals (MAX_SIZE, aCache.size ());

  // removeAll
  assertTrue (aCache.removeAll (PrimitiveCollectionHelper.newPrimitiveList (-4, -5, -6)));
  assertFalse (aCache.removeAll (PrimitiveCollectionHelper.newPrimitiveList (-4, -5, -6)));
  assertEquals (MAX_SIZE - 3, aCache.size ());

  try
  {
    aCache.retainAll (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}

  assertEquals (2, aCache.toArray ().length);
  assertEquals (2, aCache.toArray (new Integer [aCache.size ()]).length);
  aCache.clear ();
  assertEquals (0, aCache.size ());

  final LRUSet <String> ret = new LRUSet <> (4);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (ret, new LRUSet <> (4));
  ret.add ("a");
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (ret, new LRUSet <> (4));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (new LRUSet <> (3), new LRUSet <> (4));
}