Add tests to check for duplicate entries in the conversion tables

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1034797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2010-11-13 16:31:08 +00:00
parent c8c7a0c491
commit 44dbf85b6a
1 changed files with 37 additions and 0 deletions

View File

@ -17,6 +17,9 @@
package org.apache.commons.lang3.text.translate;
import java.util.HashSet;
import java.util.Set;
import junit.framework.TestCase;
/**
@ -28,4 +31,38 @@ public class EntityArraysTest extends TestCase {
public void testConstructorExists() {
new EntityArrays();
}
// LANG-659 - check arrays for duplicate entries
public void testHTML40_EXTENDED_ESCAPE(){
Set<String> col0 = new HashSet<String>();
Set<String> col1 = new HashSet<String>();
String [][] sa = EntityArrays.HTML40_EXTENDED_ESCAPE();
for(int i =0; i <sa.length; i++){
assertTrue("Already added entry 0: "+i+" "+sa[i][0],col0.add(sa[i][0]));
assertTrue("Already added entry 1: "+i+" "+sa[i][1],col1.add(sa[i][1]));
}
}
// LANG-658 - check arrays for duplicate entries
public void testISO8859_1_ESCAPE(){
Set<String> col0 = new HashSet<String>();
Set<String> col1 = new HashSet<String>();
String [][] sa = EntityArrays.ISO8859_1_ESCAPE();
boolean success = true;
for(int i =0; i <sa.length; i++){
boolean add0 = col0.add(sa[i][0]);
boolean add1 = col1.add(sa[i][1]);
if (!add0) {
success = false;
System.out.println("Already added entry 0: "+i+" "+sa[i][0]+" "+sa[i][1]);
}
if (!add1) {
success = false;
System.out.println("Already added entry 1: "+i+" "+sa[i][0]+" "+sa[i][1]);
}
}
assertTrue("One or more errors detected",success);
}
}