@SuppressWarnings("null")

    protected void collectTerms(Map<String, MutableInt> terms, Iterable<Evidence> evidence) {
        for (Evidence e : evidence) {
            String value = cleanseText(e.getValue());
            if (StringUtils.isBlank(value)) {
                continue;
            }
            if (value.length() > 1000) {
                boolean trimmed = false;
                int pos = value.lastIndexOf(" ", 1000);
                if (pos > 0) {
                    value = value.substring(0, pos);
                    trimmed = true;
                } else {
                    pos = value.lastIndexOf(".", 1000);
                }
                if (!trimmed) {
                    if (pos > 0) {
                        value = value.substring(0, pos);
                        trimmed = true;
                    } else {
                        pos = value.lastIndexOf("-", 1000);
                    }
                }
                if (!trimmed) {
                    if (pos > 0) {
                        value = value.substring(0, pos);
                        trimmed = true;
                    } else {
                        pos = value.lastIndexOf("_", 1000);
                    }
                }
                if (!trimmed) {
                    if (pos > 0) {
                        value = value.substring(0, pos);
                        trimmed = true;
                    } else {
                        pos = value.lastIndexOf("/", 1000);
                    }
                }
                if (!trimmed && pos > 0) {
                    value = value.substring(0, pos);
                    trimmed = true;
                }
                if (!trimmed) {
                    value = value.substring(0, 1000);
                }
            }
            addTerm(terms, value);
        }
    }
@Test
    public void testAddEvidenceWithoutDuplicateTerms() {
        Map<String, MutableInt> terms = new HashMap<>();
        List<Evidence> evidence = new ArrayList<>();
        evidence.add(new Evidence("test case", "value", "test", Confidence.HIGHEST));
        CPEAnalyzer instance = new CPEAnalyzer();
        String expResult = "test";
        int expValue = 1;
        instance.collectTerms(terms, evidence);
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        evidence = new ArrayList<>();
        evidence.add(new Evidence("test case", "value", "other", Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expResult = "other";
        expValue = 1;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        evidence.clear();
        evidence.add(new Evidence("test case", "value", "other", Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expResult = "other";
        expValue = 2;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        StringBuilder sb = new StringBuilder();
        StringBuilder expect = new StringBuilder();
        for (int x = 0; x < 500; x++) {
            sb.append("items ");
            if (expect.length() + 5 < 1000) {
                expect.append("items ");
            }
        }
        evidence.clear();
        terms.clear();
        evidence.add(new Evidence("test case", "value", sb.toString(), Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expResult = expect.toString().trim();
        expValue = 1;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        sb = new StringBuilder();
        expect = new StringBuilder();
        for (int x = 0; x < 500; x++) {
            sb.append("items.");
            if (expect.length() + 5 < 1000) {
                expect.append("items.");
            }
        }
        evidence.clear();
        terms.clear();
        evidence.add(new Evidence("test case", "value", sb.toString(), Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expect.setLength(expect.length() - 1);
        expResult = expect.toString();
        expValue = 1;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        sb = new StringBuilder();
        expect = new StringBuilder();
        for (int x = 0; x < 500; x++) {
            sb.append("items-");
            if (expect.length() + 5 < 1000) {
                expect.append("items-");
            }
        }
        evidence.clear();
        terms.clear();
        evidence.add(new Evidence("test case", "value", sb.toString(), Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expect.setLength(expect.length() - 1);
        expResult = expect.toString();
        expValue = 1;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        sb = new StringBuilder();
        expect = new StringBuilder();
        for (int x = 0; x < 500; x++) {
            sb.append("items_");
            if (expect.length() + 5 < 1000) {
                expect.append("items_");
            }
        }
        evidence.clear();
        terms.clear();
        evidence.add(new Evidence("test case", "value", sb.toString(), Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expect.setLength(expect.length() - 1);
        expResult = expect.toString();
        expValue = 1;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());

        sb = new StringBuilder();
        expect = new StringBuilder();
        for (int x = 0; x < 500; x++) {
            sb.append("items/");
            if (expect.length() + 5 < 1000) {
                expect.append("items/");
            }
        }
        evidence.clear();
        terms.clear();
        evidence.add(new Evidence("test case", "value", sb.toString(), Confidence.HIGHEST));
        instance.collectTerms(terms, evidence);
        expect.setLength(expect.length() - 1);
        expResult = expect.toString();
        expValue = 1;
        assertTrue(terms.containsKey(expResult));
        assertEquals(expValue, terms.get(expResult).intValue());
    }