/** * Determine if the current line (or buffered concatenation of lines) * contains an unterminated quote, indicating that the record is continuing * onto the next line. * * @param line * @return */ private boolean isQuoteUnterminated(String line) { return StringUtils.countOccurrencesOf(line, quoteCharacter) % 2 != 0; }
/** * True if the line can be parsed to a JSON object. * * @see RecordSeparatorPolicy#isEndOfRecord(String) */ @Override public boolean isEndOfRecord(String line) { return StringUtils.countOccurrencesOf(line, "{") == StringUtils.countOccurrencesOf(line, "}") && line.trim().endsWith("}"); }
@Benchmark public int countOccurrencesOf() { // Using Spring Framework's return org.springframework.util.StringUtils.countOccurrencesOf(testString, "."); }
@Benchmark public int countOccurrencesOf() { // Using Spring Framework's return org.springframework.util.StringUtils.countOccurrencesOf(testString, "."); }
if (currPath.endsWith("/") && (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, "/") <= StringUtils.countOccurrencesOf(fullPattern, "/"))) {
@Test public void testCountOccurrencesOf() { assertTrue("nullx2 = 0", StringUtils.countOccurrencesOf(null, null) == 0); assertTrue("null string = 0", StringUtils.countOccurrencesOf("s", null) == 0); assertTrue("null substring = 0", StringUtils.countOccurrencesOf(null, "s") == 0); String s = "erowoiueoiur"; assertTrue("not found = 0", StringUtils.countOccurrencesOf(s, "WERWER") == 0); assertTrue("not found char = 0", StringUtils.countOccurrencesOf(s, "x") == 0); assertTrue("not found ws = 0", StringUtils.countOccurrencesOf(s, " ") == 0); assertTrue("not found empty string = 0", StringUtils.countOccurrencesOf(s, "") == 0); assertTrue("found char=2", StringUtils.countOccurrencesOf(s, "e") == 2); assertTrue("found substring=2", StringUtils.countOccurrencesOf(s, "oi") == 2); assertTrue("found substring=2", StringUtils.countOccurrencesOf(s, "oiu") == 2); assertTrue("found substring=3", StringUtils.countOccurrencesOf(s, "oiur") == 1); assertTrue("test last", StringUtils.countOccurrencesOf(s, "r") == 2); }
/** * <p> * Parses the provided expression, applying any transformations needed to evaluate as a SPeL expression. * </p> * * @param expression the expression to parse and transform * @return a JSR-352 transformed expression that can be evaluated by a SPeL parser */ public String parseExpression(String expression) { String expressionToParse = expression; if (StringUtils.countOccurrencesOf(expressionToParse, ELVIS_OPERATOR) > 0) { expressionToParse = parseConditionalExpressions(expressionToParse); } return evaluateExpression(expressionToParse); }
@Test public void testSpringArtifactUniqueness() throws Exception { JobExecution jobExecution = runJob("jsrSpringInstanceTests", new Properties(), 10000L); String exitStatus = jobExecution.getExitStatus(); assertTrue("Exit status must contain listener1", exitStatus.contains("listener1")); assertTrue("exitStatus must contain 2 listener1 values", StringUtils.countOccurrencesOf(exitStatus, "listener1") == 2); exitStatus = exitStatus.replace("listener1", ""); assertTrue("Exit status must contain listener4", exitStatus.contains("listener4")); assertTrue("exitStatus must contain 2 listener4 values", StringUtils.countOccurrencesOf(exitStatus, "listener4") == 2); exitStatus = exitStatus.replace("listener4", ""); assertTrue("exitStatus must be empty", "".equals(exitStatus)); }
/** * Check that Properties can be comma delimited with extra whitespace. */ @Test public void testShortConversionWithCommas() { Properties storedProps = new Properties(); storedProps.setProperty("key1", "value1"); storedProps.setProperty("key2", "value2"); String value = PropertiesConverter.propertiesToString(storedProps); assertTrue("Wrong value: "+value, value.contains("key1=value1")); assertTrue("Wrong value: "+value, value.contains("key2=value2")); assertEquals(1, StringUtils.countOccurrencesOf(value, ",")); }
@Test public void testRefScopedProxy() throws Exception { assertNotNull(ref); ref.execute(new JobExecution(1L)); assertEquals(4, TestAdvice.names.size()); assertEquals("spam", TestAdvice.names.get(0)); assertEquals(2, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "bar:destroyed")); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "spam:destroyed")); }
@Test public void testGenerateLimitJumpQueryDescending() { sortKeys.put("ID", Order.DESCENDING); AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys); String query = SqlPagingQueryUtils.generateLimitJumpToQuery(qp, "LIMIT 100, 1"); assertTrue("Wrong query: " + query, query.contains("ID DESC")); assertEquals("Wrong query: " + query, 0, StringUtils.countOccurrencesOf(query, "ASC")); assertEquals("Wrong query: " + query, 1, StringUtils.countOccurrencesOf(query, "DESC")); qp.setWhereClause("BAZ IS NOT NULL"); assertTrue("Wrong query: " + query, query.contains("ID DESC")); }
@Test public void testGenerateTopJumpQueryDescending() { sortKeys.put("ID", Order.DESCENDING); AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys); String query = SqlPagingQueryUtils.generateTopJumpToQuery(qp, "TOP 100, 1"); assertTrue("Wrong query: " + query, query.contains("ID DESC")); assertEquals("Wrong query: " + query, 0, StringUtils.countOccurrencesOf(query, "ASC")); assertEquals("Wrong query: " + query, 1, StringUtils.countOccurrencesOf(query, "DESC")); qp.setWhereClause("BAZ IS NOT NULL"); assertTrue("Wrong query: " + query, query.contains("ID DESC")); }
@Test public void testDump() { SystemProperties props = new SystemProperties(); /* * No intend to test TypeSafe's render functionality. Perform * some high-level asserts to verify that: * - it's probably a config * - it's probably fairly sized * - it didn't break */ String dump = props.dump().trim(); assertTrue(dump.startsWith("{")); assertTrue(dump.endsWith("}")); assertTrue(dump.length() > 5 * 1024); assertTrue(StringUtils.countOccurrencesOf(dump, "{") > 50); assertTrue(StringUtils.countOccurrencesOf(dump, "{") > 50); }
@Test public void testRefScopedProxy() throws Exception { assertNotNull(ref); ref.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(4, TestAdvice.names.size()); assertEquals("spam", TestAdvice.names.get(0)); assertEquals(2, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "bar:destroyed")); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "spam:destroyed")); }
@Test public void testProxiedScopedProxy() throws Exception { assertNotNull(nested); nested.execute(new JobExecution(1L)); assertEquals(4, TestAdvice.names.size()); assertEquals("bar", TestAdvice.names.get(0)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testProxiedScopedProxy() throws Exception { assertNotNull(nested); nested.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(4, TestAdvice.names.size()); assertEquals("bar", TestAdvice.names.get(0)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testDisposableScopedProxy() throws Exception { assertNotNull(proxied); proxied.execute(new JobExecution(1L)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testDisposableInnerScopedProxy() throws Exception { assertNotNull(nested); nested.execute(new JobExecution(1L)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testDisposableScopedProxy() throws Exception { assertNotNull(proxied); proxied.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testDisposableInnerScopedProxy() throws Exception { assertNotNull(nested); nested.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }