Java Code Examples for com.helger.commons.mock.CommonsTestHelper#testDefaultSerialization()
The following examples show how to use
com.helger.commons.mock.CommonsTestHelper#testDefaultSerialization() .
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: SessionSingletonFuncTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testBasicWithScopeCtor () { assertTrue (AbstractSessionSingleton.getAllSessionSingletons ().isEmpty ()); assertFalse (AbstractSessionSingleton.isSessionSingletonInstantiated (MockSessionSingletonWithScopeCtor.class)); assertNull (AbstractSessionSingleton.getSessionSingletonIfInstantiated (MockSessionSingletonWithScopeCtor.class)); final MockSessionSingletonWithScopeCtor a = MockSessionSingletonWithScopeCtor.getInstance (); assertNotNull (a); assertTrue (AbstractSessionSingleton.isSessionSingletonInstantiated (MockSessionSingletonWithScopeCtor.class)); assertSame (a, AbstractSessionSingleton.getSessionSingletonIfInstantiated (MockSessionSingletonWithScopeCtor.class)); assertNotNull (a.getScope ()); assertEquals (0, a.get ()); a.inc (); assertEquals (1, a.get ()); assertSame (a, MockSessionSingletonWithScopeCtor.getInstance ()); CommonsTestHelper.testDefaultSerialization (a); }
Example 2
Source File: TypedObjectTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 3
Source File: CommonsWeakHashMapTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testBasic () { final ICommonsMap <String, String> aTest = new CommonsWeakHashMap <> (); 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)); if (false) CommonsTestHelper.testDefaultSerialization (aTest); CommonsTestHelper.testGetClone (aTest); }
Example 4
Source File: SessionSingletonFuncTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testBasic () { assertTrue (AbstractSessionSingleton.getAllSessionSingletons ().isEmpty ()); assertFalse (AbstractSessionSingleton.isSessionSingletonInstantiated (MockSessionSingleton.class)); assertNull (AbstractSessionSingleton.getSessionSingletonIfInstantiated (MockSessionSingleton.class)); final MockSessionSingleton a = MockSessionSingleton.getInstance (); assertTrue (AbstractSessionSingleton.isSessionSingletonInstantiated (MockSessionSingleton.class)); assertSame (a, AbstractSessionSingleton.getSessionSingletonIfInstantiated (MockSessionSingleton.class)); assertEquals (0, a.get ()); a.inc (); assertEquals (1, a.get ()); assertSame (a, MockSessionSingleton.getInstance ()); CommonsTestHelper.testDefaultSerialization (a); }
Example 5
Source File: ErrorListTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testSerialize () { final ErrorList aList = new ErrorList (); CommonsTestHelper.testDefaultSerialization (aList); aList.add (SingleError.builderInfo () .setErrorID ("test-1") .setErrorFieldName ("field1") .setErrorText ("TestInfo") .setErrorLocation (new SimpleLocation ("here.xml", 17, 3)) .build ()); CommonsTestHelper.testDefaultSerialization (aList); aList.add (SingleError.builderInfo () .setErrorID ("test-2") .setErrorFieldName ("field1") .setErrorText ("TestInfo") .setErrorLocation (new SimpleLocation ("here.xml", 17, 3)) .setLinkedException (new MockIOException ("Mock")) .build ()); CommonsTestHelper.testDefaultSerialization (aList); }
Example 6
Source File: HttpHeaderMapTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 7
Source File: CommonsCopyOnWriteArraySetTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testBasic () { final ICommonsSet <String> aTest = new CommonsCopyOnWriteArraySet <> (); 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: HttpHeaderMapTest.java From ph-commons with Apache License 2.0 | 6 votes |
@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 9
Source File: CommonsEnumMapTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testBasic () { final ICommonsMap <EChange, String> aTest = new CommonsEnumMap <> (EChange.class); aTest.put (EChange.UNCHANGED, "blb"); aTest.put (EChange.CHANGED, "bla"); final ICommonsOrderedSet <EChange> aSortedKeys = aTest.getSortedByKey (Comparator.naturalOrder ()).copyOfKeySet (); assertEquals (EChange.CHANGED, aSortedKeys.getAtIndex (0)); assertEquals (EChange.UNCHANGED, aSortedKeys.getAtIndex (1)); CommonsTestHelper.testDefaultSerialization (aTest); CommonsTestHelper.testGetClone (aTest); }
Example 10
Source File: JsonValueTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testSerialize () { CommonsTestHelper.testDefaultSerialization (JsonValue.create (true)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (false)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Boolean.TRUE)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Boolean.FALSE)); CommonsTestHelper.testDefaultSerialization (JsonValue.create ((byte) 5)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Byte.valueOf ((byte) -5))); CommonsTestHelper.testDefaultSerialization (JsonValue.create ('x')); CommonsTestHelper.testDefaultSerialization (JsonValue.create (31.4d)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (31.4f)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Integer.MIN_VALUE)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Integer.MAX_VALUE)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Integer.valueOf (47))); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Long.MIN_VALUE)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Long.MAX_VALUE)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Long.valueOf (Long.MAX_VALUE))); CommonsTestHelper.testDefaultSerialization (JsonValue.create ((short) 815)); CommonsTestHelper.testDefaultSerialization (JsonValue.create (Short.valueOf ((short) 815))); CommonsTestHelper.testDefaultSerialization (JsonValue.create ("Test")); CommonsTestHelper.testDefaultSerialization (JsonValue.create ("bla\r\nfoo\r\nfasel")); CommonsTestHelper.testDefaultSerialization (JsonValue.create (new BigInteger ("123456789012345678901234567890"))); CommonsTestHelper.testDefaultSerialization (JsonValue.create (BigInteger.valueOf (Long.MIN_VALUE) .subtract (BigInteger.ONE))); CommonsTestHelper.testDefaultSerialization (JsonValue.create (BigInteger.valueOf (Long.MAX_VALUE) .add (BigInteger.ONE))); CommonsTestHelper.testDefaultSerialization (JsonValue.create (new BigDecimal ("123456789012345678901234567890.8"))); }
Example 11
Source File: CommonsArrayListTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testBasic () { final ICommonsList <String> aTest = new CommonsArrayList <> (); assertTrue (aTest.isEmpty ()); aTest.add ("aaa"); aTest.add ("bbb"); aTest.add ("ccc"); CommonsTestHelper.testDefaultSerialization (aTest); CommonsTestHelper.testGetClone (aTest); }
Example 12
Source File: HttpHeaderMapTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testAddAllHeadersPrefilledDifferentCasing () { final HttpHeaderMap h = new HttpHeaderMap (); // First header defines the casing! h.addHeader ("Key1", "val1"); h.addHeader ("KEY1", "val2"); h.addHeader ("KEY1", "val3"); final HttpHeaderMap h2 = new HttpHeaderMap (); h2.addIntHeader ("key2", 42); h2.addAllHeaders (h); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (h2, h); assertEquals (4, h2.getAllHeaderLines (true).size ()); assertEquals ("key2: 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)); assertEquals (4, h2.getAllHeaderLines (false).size ()); assertEquals ("key2: 42", h2.getAllHeaderLines (false).get (0)); assertEquals ("Key1: val1", h2.getAllHeaderLines (false).get (1)); assertEquals ("Key1: val2", h2.getAllHeaderLines (false).get (2)); assertEquals ("Key1: val3", h2.getAllHeaderLines (false).get (3)); CommonsTestHelper.testGetClone (h); CommonsTestHelper.testDefaultSerialization (h); CommonsTestHelper.testGetClone (h2); CommonsTestHelper.testDefaultSerialization (h2); }
Example 13
Source File: CommonsLinkedListTest.java From ph-commons with Apache License 2.0 | 5 votes |
@Test public void testBasic () { final ICommonsList <String> aTest = new CommonsLinkedList <> (); assertTrue (aTest.isEmpty ()); aTest.add ("aaa"); aTest.add ("bbb"); aTest.add ("ccc"); CommonsTestHelper.testDefaultSerialization (aTest); CommonsTestHelper.testGetClone (aTest); }
Example 14
Source File: FileSystemResourceTest.java From ph-commons with Apache License 2.0 | 4 votes |
@Test public void testSerialize () { CommonsTestHelper.testDefaultSerialization (new FileSystemResource ("file.txt")); }
Example 15
Source File: URLResourceTest.java From ph-commons with Apache License 2.0 | 4 votes |
@Test public void testSerialize () throws Exception { CommonsTestHelper.testDefaultSerialization (new URLResource ("http://www.helger.com")); }
Example 16
Source File: HttpHeaderMapTest.java From ph-commons with Apache License 2.0 | 4 votes |
@Test public void testMultipleSimpleValues () { final HttpHeaderMap h = new HttpHeaderMap (); h.addHeader ("key1", "val1"); h.addHeader ("key2", "val2"); h.addHeader ("key3", "val3"); assertFalse (h.isEmpty ()); assertTrue (h.isNotEmpty ()); assertEquals (3, h.size ()); assertNotNull (h.getAllHeaderLines (true)); assertEquals (3, h.getAllHeaderLines (true).size ()); assertEquals ("key1: val1", h.getAllHeaderLines (true).getFirst ()); assertEquals ("key2: val2", h.getAllHeaderLines (true).get (1)); assertEquals ("key3: val3", h.getAllHeaderLines (true).get (2)); assertNotNull (h.getAllHeaderLines (false)); assertEquals (3, h.getAllHeaderLines (false).size ()); assertEquals ("key1: val1", h.getAllHeaderLines (false).getFirst ()); assertEquals ("key2: val2", h.getAllHeaderLines (false).get (1)); assertEquals ("key3: val3", h.getAllHeaderLines (false).get (2)); assertNotNull (h.getAllHeaderNames ()); assertEquals (3, h.getAllHeaderNames ().size ()); assertTrue (h.getAllHeaderNames ().contains ("key1")); assertTrue (h.getAllHeaderNames ().contains ("key2")); assertTrue (h.getAllHeaderNames ().contains ("key3")); assertNotNull (h.getAllHeaders ()); assertEquals (3, h.getAllHeaders ().size ()); assertTrue (h.getAllHeaders ().containsKey ("key1")); assertTrue (h.getAllHeaders ().containsKey ("key2")); assertTrue (h.getAllHeaders ().containsKey ("key3")); assertNotNull (h.getAllHeaderValues ("key1")); assertEquals (1, h.getAllHeaderValues ("key1").size ()); assertEquals ("val1", h.getAllHeaderValues ("key1").getFirst ()); assertNotNull (h.getAllHeaderValues ("key2")); assertEquals (1, h.getAllHeaderValues ("key2").size ()); assertEquals ("val2", h.getAllHeaderValues ("key2").getFirst ()); assertNotNull (h.getAllHeaderValues ("key3")); assertEquals (1, h.getAllHeaderValues ("key3").size ()); assertEquals ("val3", h.getAllHeaderValues ("key3").getFirst ()); assertNotNull (h.getAllHeaderValues ("KEY1")); assertEquals (1, h.getAllHeaderValues ("kEy1").size ()); assertEquals ("val1", h.getAllHeaderValues ("keY1").getFirst ()); CommonsTestHelper.testGetClone (h); CommonsTestHelper.testDefaultSerialization (h); }
Example 17
Source File: AbstractFuncTestCSSReader.java From ph-css with Apache License 2.0 | 4 votes |
protected final void testReadGood (@Nonnull final String sBaseDir) { final File aBaseDir = new File (sBaseDir); if (!aBaseDir.exists ()) throw new IllegalArgumentException ("BaseDir " + sBaseDir + " does not exist!"); for (final File aFile : new FileSystemRecursiveIterator (aBaseDir).withFilter (IFileFilter.filenameEndsWith (".css"))) { final String sKey = aFile.getAbsolutePath (); if (m_bDebug) m_aLogger.info ("Filename: " + sKey); final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler (); m_aReaderSettings.setCustomErrorHandler (aErrorHdl.and (new LoggingCSSParseErrorHandler ())); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, m_aReaderSettings); assertNotNull (sKey, aCSS); // May have errors or not if (m_bDebug) m_aLogger.info ("Parse errors: " + aErrorHdl.getAllParseErrors ().toString ()); CommonsTestHelper.testDefaultSerialization (aCSS); // Write optimized version and compare it String sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (true)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); if (m_bDebug) m_aLogger.info ("Created CSS: " + sCSS); final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader (sCSS, m_aReaderSettings); assertNotNull ("Failed to parse " + sKey + ":\n" + sCSS, aCSSReRead); assertEquals (sKey + "\n" + sCSS, aCSS, aCSSReRead); // Write non-optimized version and compare it sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (false)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); if (m_bDebug) m_aLogger.info ("Read and re-created CSS: " + sCSS); assertEquals (sKey, aCSS, CSSReader.readFromStringReader (sCSS, m_aReaderSettings)); // Write non-optimized and code-removed version and ensure it is not // null sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (false) .setRemoveUnnecessaryCode (true)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); assertNotNull (sKey, CSSReader.readFromStringReader (sCSS, m_aReaderSettings)); // Restore value :) m_aWriterSettings.setRemoveUnnecessaryCode (false); } }
Example 18
Source File: VersionTest.java From ph-commons with Apache License 2.0 | 4 votes |
@Test public void testSerialization () { CommonsTestHelper.testDefaultSerialization (new Version (1, 2, 3)); CommonsTestHelper.testDefaultSerialization (Version.parse ("1.2a")); }
Example 19
Source File: VersionRangeTest.java From ph-commons with Apache License 2.0 | 4 votes |
@Test public void testSerialization () { CommonsTestHelper.testDefaultSerialization (VersionRange.parse ("(1.2]")); CommonsTestHelper.testDefaultSerialization (VersionRange.parse ("(0)")); }
Example 20
Source File: ErrorListTest.java From ph-commons with Apache License 2.0 | 4 votes |
@Test public void testBasicGlobal () { final ErrorList aList = new ErrorList (); assertTrue (aList.isEmpty ()); assertEquals (0, aList.size ()); assertFalse (aList.containsAtLeastOneWarningOrError ()); assertEquals (EErrorLevel.SUCCESS, aList.getMostSevereErrorLevel ()); assertNotNull (aList); assertEquals (0, aList.size ()); assertNotNull (aList.getAllTexts (Locale.US)); assertEquals (0, aList.getAllTexts (Locale.US).size ()); assertNotNull (aList.getListWithoutField ()); assertEquals (0, aList.getListWithoutField ().size ()); assertFalse (aList.hasEntryForField ("field1")); assertFalse (aList.hasEntryForField (null)); assertEquals (0, aList.getListOfField ("field1").size ()); assertEquals (0, aList.getListOfField ("field2").size ()); assertEquals (0, aList.getListOfFields ("field1", "field2").size ()); assertEquals (0, aList.getListOfFieldsStartingWith ("field").size ()); assertEquals (0, aList.getListOfFieldsRegExp ("field\\d").size ()); assertEquals (0, aList.getGroupedByID ().size ()); assertEquals (0, aList.getGroupedByFieldName ().size ()); aList.add (SingleError.builderInfo ().setErrorText ("TestInfo").build ()); assertFalse (aList.isEmpty ()); assertEquals (1, aList.size ()); assertFalse (aList.containsAtLeastOneWarningOrError ()); assertEquals (EErrorLevel.INFO, aList.getMostSevereErrorLevel ()); assertNotNull (aList); assertEquals (1, aList.size ()); assertNotNull (aList.getAllTexts (Locale.US)); assertEquals (1, aList.getAllTexts (Locale.US).size ()); assertNotNull (aList.getListWithoutField ()); assertEquals (1, aList.getListWithoutField ().size ()); assertFalse (aList.hasEntryForField ("field1")); assertTrue (aList.hasEntryForField (null)); assertEquals (0, aList.getListOfField ("field1").size ()); assertEquals (0, aList.getListOfField ("field2").size ()); assertEquals (0, aList.getListOfFields ("field1", "field2").size ()); assertEquals (0, aList.getListOfFieldsStartingWith ("field").size ()); assertEquals (0, aList.getListOfFieldsRegExp ("field\\d").size ()); assertEquals (1, aList.getGroupedByID ().size ()); assertEquals (1, aList.getGroupedByFieldName ().size ()); aList.add (SingleError.builderError ().setErrorText ("TestError").build ()); assertFalse (aList.isEmpty ()); assertEquals (2, aList.size ()); assertTrue (aList.containsAtLeastOneWarningOrError ()); assertEquals (EErrorLevel.ERROR, aList.getMostSevereErrorLevel ()); assertNotNull (aList); assertEquals (2, aList.size ()); assertNotNull (aList.getAllTexts (Locale.US)); assertEquals (2, aList.getAllTexts (Locale.US).size ()); assertNotNull (aList.getListWithoutField ()); assertEquals (2, aList.getListWithoutField ().size ()); assertFalse (aList.hasEntryForField ("field1")); assertTrue (aList.hasEntryForField (null)); assertEquals (0, aList.getListOfField ("field1").size ()); assertEquals (0, aList.getListOfField ("field2").size ()); assertEquals (0, aList.getListOfFields ("field1", "field2").size ()); assertEquals (0, aList.getListOfFieldsStartingWith ("field").size ()); assertEquals (0, aList.getListOfFieldsRegExp ("field\\d").size ()); assertEquals (1, aList.getGroupedByID ().size ()); assertEquals (1, aList.getGroupedByFieldName ().size ()); aList.add (SingleError.builderWarn ().setErrorText ("TestWarning").build ()); assertFalse (aList.isEmpty ()); assertEquals (3, aList.size ()); assertTrue (aList.containsAtLeastOneWarningOrError ()); assertEquals (EErrorLevel.ERROR, aList.getMostSevereErrorLevel ()); assertNotNull (aList); assertEquals (3, aList.size ()); assertNotNull (aList.getAllTexts (Locale.US)); assertEquals (3, aList.getAllTexts (Locale.US).size ()); assertNotNull (aList.getListWithoutField ()); assertEquals (3, aList.getListWithoutField ().size ()); assertFalse (aList.hasEntryForField ("field1")); assertTrue (aList.hasEntryForField (null)); assertEquals (0, aList.getListOfField ("field1").size ()); assertEquals (0, aList.getListOfField ("field2").size ()); assertEquals (0, aList.getListOfFields ("field1", "field2").size ()); assertEquals (0, aList.getListOfFieldsStartingWith ("field").size ()); assertEquals (0, aList.getListOfFieldsRegExp ("field\\d").size ()); assertEquals (1, aList.getGroupedByID ().size ()); assertEquals (1, aList.getGroupedByFieldName ().size ()); CommonsTestHelper.testDefaultSerialization (aList); }