本文整理了Java中java.lang.String.contains()
方法的一些代码示例,展示了String.contains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.contains()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:contains
[英]Returns true if and only if this string contains the specified sequence of char values.
[中]当且仅当此字符串包含指定的字符值序列时,返回true。
代码示例来源:origin: square/okhttp
/**
* Returns true if {@code e} is due to a firmware bug fixed after Android 4.2.2.
* https://code.google.com/p/android/issues/detail?id=54072
*/
public static boolean isAndroidGetsocknameError(AssertionError e) {
return e.getCause() != null && e.getMessage() != null
&& e.getMessage().contains("getsockname failed");
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public boolean test(Throwable t) {
return t.getMessage() != null && t.getMessage().contains("Forced");
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public String apply(Integer t) throws Exception {
String name = Thread.currentThread().getName();
if (name.contains("RxSingleScheduler")) {
return "RxSingleScheduler";
}
return name;
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public boolean test(Throwable t) throws Exception {
return t.getMessage() != null && t.getMessage().contains("Forced");
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(MaybeEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(MaybeCreate.Emitter.class.getSimpleName()));
}
}).test().assertEmpty();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(SingleEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(SingleCreate.Emitter.class.getSimpleName()));
}
}).test().assertEmpty();
代码示例来源:origin: ReactiveX/RxJava
/**
* This hijacks the Throwable.printStackTrace() output and puts it in a string, where we can look for
* "CIRCULAR REFERENCE" (a String added by Throwable.printEnclosedStackTrace)
*/
private static void assertNoCircularReferences(Throwable ex) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(baos);
ex.printStackTrace(printStream);
assertFalse(baos.toString().contains("CIRCULAR REFERENCE"));
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(CompletableEmitter emitter) throws Exception {
assertTrue(emitter.toString().contains(CompletableCreate.Emitter.class.getSimpleName()));
}
}).test().assertEmpty();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(FlowableEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(entry.getValue().getSimpleName()));
assertTrue(emitter.serialize().toString().contains(entry.getValue().getSimpleName()));
}
}, entry.getKey()).test().assertEmpty();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(ObservableEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(ObservableCreate.CreateEmitter.class.getSimpleName()));
assertTrue(emitter.serialize().toString().contains(ObservableCreate.CreateEmitter.class.getSimpleName()));
}
}).test().assertEmpty();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable e) {
String trace = stackTraceAsString(e);
System.out.println("On Error: " + trace);
assertTrue(trace, trace.contains("OnNextValue"));
assertTrue("No Cause on throwable" + e, e.getCause() != null);
// assertTrue(e.getCause().getClass().getSimpleName() + " no OnNextValue",
// e.getCause() instanceof OnErrorThrowable.OnNextValue);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testOnErrorNotImplementedIsThrown() {
List<Throwable> errors = TestHelper.trackPluginErrors();
Observable.just(1, 2, 3).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer t1) {
throw new RuntimeException("hello");
}
});
TestHelper.assertError(errors, 0, RuntimeException.class);
assertTrue(errors.get(0).toString(), errors.get(0).getMessage().contains("hello"));
RxJavaPlugins.reset();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void disposeIndicated() {
TestSubscriber<Object> ts = new TestSubscriber<Object>();
ts.cancel();
try {
ts.assertResult(1);
throw new RuntimeException("Should have thrown!");
} catch (Throwable ex) {
assertTrue(ex.toString(), ex.toString().contains("disposed!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void printStackTrace() {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
new CompositeException(new TestException()).printStackTrace(pw);
assertTrue(sw.toString().contains("TestException"));
}
代码示例来源:origin: square/okhttp
public static String hostHeader(HttpUrl url, boolean includeDefaultPort) {
String host = url.host().contains(":")
? "[" + url.host() + "]"
: url.host();
return includeDefaultPort || url.port() != HttpUrl.defaultPort(url.scheme())
? host + ":" + url.port()
: host;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void assertNoTimeout2() {
try {
Flowable.never()
.test()
.awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50)
.assertNoTimeout();
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.getMessage().contains("Timeout?!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void assertTimeout2() {
try {
Flowable.empty()
.test()
.awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50)
.assertTimeout();
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.getMessage().contains("No timeout?!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeoutIndicated() throws InterruptedException {
Thread.interrupted(); // clear flag
TestSubscriber<Object> ts = Flowable.never()
.test();
assertFalse(ts.await(1, TimeUnit.MILLISECONDS));
try {
ts.assertResult(1);
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.toString().contains("timeout!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeoutIndicated2() throws InterruptedException {
try {
Flowable.never()
.test()
.awaitDone(1, TimeUnit.MILLISECONDS)
.assertResult(1);
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.toString().contains("timeout!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeoutIndicated3() throws InterruptedException {
TestSubscriber<Object> ts = Flowable.never()
.test();
assertFalse(ts.awaitTerminalEvent(1, TimeUnit.MILLISECONDS));
try {
ts.assertResult(1);
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.toString().contains("timeout!"));
}
}
内容来源于网络,如有侵权,请联系作者删除!