This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
forked from x-stream/xstream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test cases for StringConverter. Closes x-stream#187.
- Loading branch information
1 parent
b06b964
commit fd15041
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
xstream/src/test/com/thoughtworks/xstream/converters/basic/StringConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2020 XStream Committers. | ||
* All rights reserved. | ||
* | ||
* The software in this package is published under the terms of the BSD | ||
* style license a copy of which has been included with this distribution in | ||
* the LICENSE.txt file. | ||
* | ||
* Created on 12. Mar 2020 by Zezeng Wang | ||
*/ | ||
|
||
package com.thoughtworks.xstream.converters.basic; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import junit.framework.TestCase; | ||
|
||
|
||
/** | ||
* Tests {@link StringConverter}. | ||
*/ | ||
public class StringConverterTest extends TestCase { | ||
|
||
/** | ||
* Tests use of own map implementation for cache. | ||
*/ | ||
public void testOwnMapImplementationForCache() { | ||
// Using the parameter map constructor | ||
final Map<String, String> map = new ConcurrentHashMap<>(); | ||
final StringConverter converter = new StringConverter(map); | ||
assertSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // cached value | ||
assertEquals(1, map.size()); | ||
} | ||
|
||
/** | ||
* Tests cache limitation for string length. | ||
*/ | ||
public void testCacheLimitationBasedOnStringLength() { | ||
// Using the int constructor | ||
final StringConverter converter = new StringConverter(4); | ||
assertSame(converter.fromString("Test"), converter.fromString(new String("Test"))); // cached value | ||
assertNotSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // non-cached value | ||
} | ||
|
||
/** | ||
* Tests no cache. | ||
*/ | ||
public void testNoCache() { | ||
final StringConverter converter = new StringConverter(null); | ||
assertNotSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // non-cached value | ||
} | ||
|
||
/** | ||
* Tests own map implementation and string length limit for cache. | ||
*/ | ||
public void testOwnMapImplementationAndStringLegnthLimitForCache() { | ||
// Using the map and int constructor | ||
final Map<String, String> map = new ConcurrentHashMap<>(); | ||
final StringConverter converter = new StringConverter(map, 4); | ||
assertSame(converter.fromString("Test"), converter.fromString(new String("Test"))); // cached value | ||
assertNotSame(converter.fromString("JUnit"), converter.fromString(new String("JUnit"))); // non-cached value | ||
assertEquals(1, map.size()); | ||
} | ||
} |