WordNetDictionary { public boolean isValidTerm(String input) { if (input == null) { return false; } final String[] tokens = TextUtils.cutTextAndSplit(input); for (String token : tokens) { if (!isValidWord(token)) { return false; } } return true; } private  WordNetDictionary(); static WordNetDictionary getInstance(); boolean isValidTerm(String input); void close();  }
@Test public void testIsValidTerm() { assertTrue(wordnet.isValidTerm("talent")); assertTrue(wordnet.isValidTerm("PostalCode")); assertTrue(wordnet.isValidTerm("CodePostal")); assertTrue(wordnet.isValidTerm("Postal Code")); assertTrue(wordnet.isValidTerm("CareOfName")); assertFalse(wordnet.isValidTerm("foobar")); assertFalse(wordnet.isValidTerm("country_code")); assertFalse(wordnet.isValidTerm("Code_Postal")); assertFalse(wordnet.isValidTerm("CodePays")); assertFalse(wordnet.isValidTerm(null)); }
@Test public void testIsValidTermMultiThread() throws InterruptedException { final AtomicBoolean atomBoolean = new AtomicBoolean(true); final String[] validTerms = new String[] { "talent", "PostalCode", "CodePostal", "CareOfName" }; Runnable runable1 = new Runnable() { @Override public void run() { try { for (String term : validTerms) { boolean flag = wordnet.isValidTerm(term); assertTrue("the term <" + term + "> is expected to be valid", flag); } } catch (Exception exc) { atomBoolean.set(false); } catch (AssertionError error) { LOGGER.error("Assertion Error: " + error.getMessage()); atomBoolean.set(false); } } }; final String[] invalidTerms = new String[] { "foobar", "country_code", "Code_Postal", "CodePays" }; Runnable runable2 = new Runnable() { @Override public void run() { try { for (String term : invalidTerms) { boolean flag = wordnet.isValidTerm(term); assertFalse("the term <" + term + "> is expected to be invalid", flag); } } catch (Exception exc) { atomBoolean.set(false); } catch (AssertionError error) { LOGGER.error("Assertion Error: " + error.getMessage()); atomBoolean.set(false); } } }; List<Thread> workers = new ArrayList<>(); for (int i = 0; i < 20; i++) { workers.add(new Thread(runable1)); workers.add(new Thread(runable2)); } for (Thread worker : workers) { worker.start(); } for (Thread worker : workers) { worker.join(); } assertEquals("ConcurrentAccess failed", true, atomBoolean.get()); }