AbstractRule implements Validator<Patent> { @Override public boolean test(Patent patent) { PatentDocFormat docFormat = PatentDocFormatDetect.fromPatent(patent); if (!PatentType.DESIGN.equals(patent.getPatentType())) { StringTokenizer tokenizer = tokenize(patent.getAbstract().getPlainText()); int tokens = tokenizer.countTokens(); if (patent.getAbstract() == null || patent.getAbstract().getPlainText().length() < 10) { MESSAGE = MESSAGE + " BELOW MINIMUM SIZE: 10; " + patent.getAbstract().getPlainText(); return false; } else if ((PatentDocFormat.RedbookGrant.equals(docFormat) || PatentDocFormat.RedbookApplication.equals(docFormat)) && tokens > 150) { MESSAGE = MESSAGE + " REDBOOK XML : ABOVE MAX WORD SIZE: 150; " + patent.getAbstract().getPlainText(); return false; } else if (tokens > 500) { MESSAGE = MESSAGE + " ABOVE MAX WORD SIZE: 500; " + patent.getAbstract().getPlainText(); return false; } } return true; }  @Override boolean test(Patent patent); @Override String getName(); @Override String getMessage(); StringTokenizer tokenize(String text);  }
@Test public void failTooSmall() { PatentApplication patent = new PatentApplication(new DocumentId(CountryCode.US, "99999"), PatentType.UTILITY); Abstract abst = new Abstract("", new DummyFormattedText()); patent.setAbstract(abst); assertFalse(abstractRule.test(patent)); }
@Test public void failTooLarge() { StringBuilder stb = new StringBuilder(); for (int i = 0; i < 501; i++) { stb.append(RandomStringUtils.randomAlphabetic(3, 7)).append(" "); } String largeAbstractTxt = stb.toString(); PatentApplication patent = new PatentApplication(new DocumentId(CountryCode.US, "99999"), PatentType.UTILITY); Abstract abst = new Abstract(largeAbstractTxt, new DummyFormattedText()); patent.setAbstract(abst); assertFalse(abstractRule.test(patent)); }
@Test public void passLenGood() { String abstractTxt = "The United States Patent and Trademark Office (USPTO) is an agency in the U.S. Department of Commerce that issues patents to inventors and businesses for their inventions, and trademark registration for product and intellectual property identification. The USPTO is unique among federal agencies because it operates solely on fees collected by its users, and not on taxpayer dollars.[2]"; PatentApplication patent = new PatentApplication(new DocumentId(CountryCode.US, "99999"), PatentType.UTILITY); Abstract abst = new Abstract(abstractTxt, new DummyFormattedText()); patent.setAbstract(abst); assertTrue(abstractRule.test(patent)); }