-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to fix thread-safety of CharacterProtector
* Add simple unit tests for class. Fixes Issue # 20. Signed-off-by: Alex Coles <alex@alexbcoles.com>
- Loading branch information
Showing
2 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
core/src/test/java/org/markdownj/test/CharacterProtectorTest.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,52 @@ | ||
package org.markdownj.test; | ||
|
||
import java.util.Collection; | ||
import static org.junit.Assert.*; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.markdownj.CharacterProtector; | ||
|
||
/** | ||
* | ||
* @author alexbcoles | ||
*/ | ||
public class CharacterProtectorTest { | ||
|
||
private CharacterProtector characterProtector; | ||
|
||
@Before | ||
public void createCharacterProtector() { | ||
characterProtector = new CharacterProtector(); | ||
} | ||
|
||
@Test | ||
public void testEncodeAndDecodeRoundtrip() { | ||
String encoded = characterProtector.encode("<h4>Warnemünde</h4>"); | ||
assertEquals("<h4>Warnemünde</h4>", characterProtector.decode(encoded)); | ||
} | ||
|
||
@Test | ||
public void testGetAllEncodedTokens() { | ||
Collection tokens = characterProtector.getAllEncodedTokens(); | ||
assertEquals(0, tokens.size()); | ||
|
||
characterProtector.encode("<nav><div></div></nav>"); | ||
characterProtector.encode("<h1 id='heading'>Schifffahrt nach Warnemünde</h1>"); | ||
characterProtector.encode("<br/>"); | ||
assertEquals(3, tokens.size()); | ||
} | ||
|
||
@Test(expected=UnsupportedOperationException.class) | ||
public void testGetAllEncodedTokensCanNotModified1() { | ||
Collection tokens = characterProtector.getAllEncodedTokens(); | ||
tokens.clear(); | ||
} | ||
|
||
@Test(expected=UnsupportedOperationException.class) | ||
public void testGetAllEncodedTokensCanNotModified2() { | ||
Collection tokens = characterProtector.getAllEncodedTokens(); | ||
tokens.add("another_token"); | ||
tokens.remove("another_token"); | ||
} | ||
|
||
} |