Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 33D8C200C13 for ; Mon, 23 Jan 2017 02:28:05 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3296A160B5F; Mon, 23 Jan 2017 01:28:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 601A2160B59 for ; Mon, 23 Jan 2017 02:28:04 +0100 (CET) Received: (qmail 40388 invoked by uid 500); 23 Jan 2017 01:28:03 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 40361 invoked by uid 99); 23 Jan 2017 01:28:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jan 2017 01:28:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4391ADFCBD; Mon, 23 Jan 2017 01:28:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chtompki@apache.org To: commits@commons.apache.org Date: Mon, 23 Jan 2017 01:28:04 -0000 Message-Id: <81da96c487094f5bbde719ca3b613f5f@git.apache.org> In-Reply-To: <66476b5971e04b079d8d9f2e23fa543e@git.apache.org> References: <66476b5971e04b079d8d9f2e23fa543e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/8] [text] TEXT-58: Strenthening the unit tests for EntityArrays, defence agains lack of readability archived-at: Mon, 23 Jan 2017 01:28:05 -0000 TEXT-58: Strenthening the unit tests for EntityArrays, defence agains lack of readability Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/ddd93aa6 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/ddd93aa6 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/ddd93aa6 Branch: refs/heads/master Commit: ddd93aa6a36ff7483ac78e29f8b552cf5ae984a3 Parents: 5bea132 Author: Rob Tompkins Authored: Sat Jan 21 10:07:14 2017 -0500 Committer: Rob Tompkins Committed: Sat Jan 21 10:07:14 2017 -0500 ---------------------------------------------------------------------- .../text/translate/EntityArraysTest.java | 104 +++++++++++-------- 1 file changed, 61 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/ddd93aa6/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java b/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java index 2a9ddd9..6b4a0ca 100644 --- a/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java +++ b/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java @@ -19,83 +19,101 @@ package org.apache.commons.text.translate; import org.junit.Test; -import java.util.HashSet; +import java.io.BufferedReader; +import java.io.FileReader; import java.util.Map; -import java.util.Set; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** - * Unit tests for {@link org.apache.commons.text.translate.EntityArrays}. + * Unit tests for {@link EntityArrays}. */ public class EntityArraysTest { @Test public void testConstructorExists() { - new org.apache.commons.text.translate.EntityArrays(); + new EntityArrays(); } - // LANG-659 - check arrays for duplicate entries + // LANG-659, LANG-658 - avoid duplicate entries @Test - public void testHTML40_EXTENDED_ESCAPE(){ - final Set col0 = new HashSet<>(); - final Set col1 = new HashSet<>(); - final String [][] sa = org.apache.commons.text.translate.EntityArrays.HTML40_EXTENDED_ESCAPE(); - for(int i =0; i ();")) { + mapDeclarationCounter = 0; + } else if (line.contains(".put(")) { + mapDeclarationCounter++; + } else if (line.contains("Collections.unmodifiableMap(initialMap);")) { + String mapVariableName = line.split("=")[0].trim(); + Map mapValue = (Map)EntityArrays.class.getDeclaredField(mapVariableName).get(EntityArrays.class); + // Validate that we are not inserting into the same key twice in the map declaration. If this, + // indeed was the case the keySet().size() would be smaller than the number of put() statements + assertEquals(mapDeclarationCounter, mapValue.keySet().size()); + } + } } } - // LANG-658 - check arrays for duplicate entries @Test - public void testISO8859_1_ESCAPE(){ - final Set col0 = new HashSet<>(); - final Set col1 = new HashSet<>(); - final String [][] sa = EntityArrays.ISO8859_1_ESCAPE(); - boolean success = true; - for(int i =0; i escapeMap, final Map unescapeMap) { + private void testEscapeVsUnescapeMaps(final Map escapeMap, final Map unescapeMap) { for (final String escapeKey : escapeMap.keySet()) { for (final String unescapeKey : unescapeMap.keySet()) { if (escapeKey == unescapeMap.get(unescapeKey)) {