本文整理了Java中com.google.common.truth.Subject.named()
方法的一些代码示例,展示了Subject.named()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Subject.named()
方法的具体详情如下:
包路径:com.google.common.truth.Subject
类名称:Subject
方法名:named
[英]Renames the subject so that this name appears in the error messages in place of string representations of the subject.
[中]重命名主题,以便此名称出现在错误消息中,而不是主题的字符串表示形式。
代码示例来源:origin: robolectric/robolectric
@Test
public void getMainLooper_shouldBeInitialized_onBackgroundThread_evenWhenRobolectricApplicationIsNull() throws Exception {
RuntimeEnvironment.application = null;
final AtomicReference<Looper> mainLooperAtomicReference = new AtomicReference<>();
Thread backgroundThread = new Thread(new Runnable() {
@Override
public void run() {
Looper mainLooper = Looper.getMainLooper();
mainLooperAtomicReference.set(mainLooper);
}
}, testName.getMethodName());
backgroundThread.start();
backgroundThread.join();
assertThat(mainLooperAtomicReference.get()).named("mainLooper").isSameAs(Looper.getMainLooper());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reset_shouldEmptyMessagePool() {
Message dummy1 = Message.obtain();
shadowOf(dummy1).recycleUnchecked();
Message dummy2 = Message.obtain();
assertThat(dummy2).named("before resetting").isSameAs(dummy1);
shadowOf(dummy2).recycleUnchecked();
ShadowMessage.reset();
dummy1 = Message.obtain();
assertThat(dummy1).named("after resetting").isNotSameAs(dummy2);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSetUpSystemResources() {
Resources systemResources = Resources.getSystem();
Resources appResources = ApplicationProvider.getApplicationContext().getResources();
assertThat(systemResources).named("system resources").isNotNull();
assertThat(systemResources.getString(android.R.string.copy)).named("system resource")
.isEqualTo(appResources.getString(android.R.string.copy));
assertThat(appResources.getString(R.string.howdy)).named("app resource")
.isNotNull();
try {
systemResources.getString(R.string.howdy);
fail("Expected Exception not thrown");
} catch (Resources.NotFoundException e) {
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void test_setGetHead() {
shadowQueue.setHead(testMessage);
assertThat(shadowQueue.getHead()).named("getHead()").isSameAs(testMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void enqueueMessage_setsHead() {
enqueueMessage(testMessage, 100);
assertThat(shadowQueue.getHead()).named("head").isSameAs(testMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetDataSourceString() throws IOException {
DataSource ds = toDataSource("dummy");
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource("dummy");
assertThat(shadowMediaPlayer.getDataSource()).named("dataSource").isEqualTo(ds);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldInitializeAndBindApplicationButNotCallOnCreate() {
assertThat((Application) ApplicationProvider.getApplicationContext())
.named("application")
.isInstanceOf(MyTestApplication.class);
assertThat(((MyTestApplication) ApplicationProvider.getApplicationContext()).onCreateWasCalled)
.named("onCreate called")
.isTrue();
if (RuntimeEnvironment.useLegacyResources()) {
assertThat(RuntimeEnvironment.getAppResourceTable())
.named("Application resource loader")
.isNotNull();
}
}
代码示例来源:origin: robolectric/robolectric
@Override
public void handleMessage(Message msg) {
boolean inUse = callInstanceMethod(msg, "isInUse");
assertThat(inUse).named(msg.what + ":inUse").isTrue();
Message next = reflector(_Message_.class, msg).getNext();
assertThat(next).named(msg.what + ":next").isNull();
}
};
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetDataSourceUri() throws IOException {
Map<String, String> headers = new HashMap<>();
Uri uri = Uri.parse("file:/test");
DataSource ds = toDataSource(ApplicationProvider.getApplicationContext(), uri, headers);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(ApplicationProvider.getApplicationContext(), uri, headers);
assertThat(shadowMediaPlayer.getSourceUri()).named("sourceUri").isSameAs(uri);
assertThat(shadowMediaPlayer.getDataSource()).named("dataSource").isEqualTo(ds);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetDataSourceFD() throws IOException {
File tmpFile = File.createTempFile("MediaPlayerTest", null);
try {
tmpFile.deleteOnExit();
FileInputStream is = new FileInputStream(tmpFile);
try {
FileDescriptor fd = is.getFD();
DataSource ds = toDataSource(fd, 23, 524);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(fd, 23, 524);
assertThat(shadowMediaPlayer.getSourceUri()).named("sourceUri").isNull();
assertThat(shadowMediaPlayer.getDataSource()).named("dataSource")
.isEqualTo(ds);
} finally {
is.close();
}
} finally {
tmpFile.delete();
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldResetQueue_whenLooperIsReset() {
HandlerThread ht = getHandlerThread();
Looper looper = ht.getLooper();
Handler h = new Handler(looper);
ShadowLooper sLooper = shadowOf(looper);
sLooper.pause();
h.post(new Runnable() {
@Override
public void run() {
}
});
assertThat(shadowOf(looper.getQueue()).getHead()).named("queue").isNotNull();
sLooper.reset();
assertThat(sLooper.getScheduler().areAnyRunnable()).named("areAnyRunnable").isFalse();
assertThat(shadowOf(looper.getQueue()).getHead()).named("queue").isNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void scheduler_wontDispatchRemovedMessage_evenIfMessageReused() {
final ArrayList<Long> runAt = new ArrayList<>();
ShadowLooper.pauseMainLooper();
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
runAt.add(shadowOf(Looper.myLooper()).getScheduler().getCurrentTime());
}
};
final long startTime = Robolectric.getForegroundThreadScheduler().getCurrentTime();
Message msg = handler.obtainMessage(123);
handler.sendMessageDelayed(msg, 200);
handler.removeMessages(123);
Message newMsg = handler.obtainMessage(123);
assertThat(newMsg).named("new message").isSameAs(msg);
handler.sendMessageDelayed(newMsg, 400);
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
// Original implementation had a bug which caused reused messages to still
// be invoked at their original post time.
assertThat(runAt).named("handledAt").containsExactly(startTime + 400L);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void soStaticRefsToLoopersInAppWorksAcrossTests_shouldRetainSameLooperForMainThreadBetweenResetsButGiveItAFreshScheduler() throws Exception {
Looper mainLooper = Looper.getMainLooper();
Scheduler scheduler = shadowOf(mainLooper).getScheduler();
shadowOf(mainLooper).quit = true;
assertThat(ApplicationProvider.getApplicationContext().getMainLooper()).isSameAs(mainLooper);
Scheduler s = new Scheduler();
RuntimeEnvironment.setMasterScheduler(s);
ShadowLooper.resetThreadLoopers();
Application application = new Application();
ReflectionHelpers.callInstanceMethod(
application,
"attach",
ReflectionHelpers.ClassParameter.from(
Context.class,
((Application) ApplicationProvider.getApplicationContext()).getBaseContext()));
assertThat(Looper.getMainLooper()).named("Looper.getMainLooper()").isSameAs(mainLooper);
assertThat(application.getMainLooper()).named("app.getMainLooper()").isSameAs(mainLooper);
assertThat(shadowOf(mainLooper).getScheduler()).named("scheduler").isNotSameAs(scheduler);
assertThat(shadowOf(mainLooper).getScheduler()).named("scheduler").isSameAs(s);
assertThat(shadowOf(mainLooper).hasQuit()).named("quit").isFalse();
}
代码示例来源:origin: googleapis/google-cloud-java
assertThat(binderMethod).named("Binder for " + method.toString()).isNotNull();
代码示例来源:origin: robolectric/robolectric
ShadowMediaPlayer.setCreateListener(createListener);
assertThat(ShadowMediaPlayer.createListener)
.named("createListener")
.isSameAs(createListener);
DataSource dummy = toDataSource("stuff");
assertThat(shadowMediaPlayer.getMediaInfo()).named("mediaInfo:before").isNotNull();
.named("createListener")
.isNull();
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldThrowawayRunnableQueueIfLooperQuits() throws Exception {
HandlerThread ht = getHandlerThread();
Looper looper = ht.getLooper();
shadowOf(looper).pause();
shadowOf(looper).post(new Runnable() {
@Override
public void run() {
}
}, 0);
looper.quit();
assertThat(shadowOf(looper).hasQuit()).named("hasQuit").isTrue();
assertThat(shadowOf(looper).getScheduler().areAnyRunnable()).named("areAnyRunnable").isFalse();
assertThat(shadowOf(looper.getQueue()).getHead()).named("queue").isNull();
}
代码示例来源:origin: inferred/FreeBuilder
private static void assertPropertyHasAnnotation(
Property property, Class<? extends Annotation> annotationClass, String annotationString) {
Excerpt annotationExcerpt = property.getAccessorAnnotations()
.stream()
.filter(excerpt -> asCompilableString(excerpt)
.contains(annotationClass.getCanonicalName()))
.findFirst()
.orElse(null);
assertThat(annotationExcerpt).named("property accessor annotations").isNotNull();
assertThat(asString(annotationExcerpt)).contains(String.format("%s%n", annotationString));
}
代码示例来源:origin: org.truth0/truth
/**
* Soft-deprecated in favor of {@link #named(String)}.
*/
public S labeled(String label) {
return named(label);
}
代码示例来源:origin: org.truth0/truth
@Override public S named(String name) { return (S)super.named(name); }
代码示例来源:origin: org.truth0/truth
public OptionalSubject(FailureStrategy failureStrategy, Optional<T> subject) {
super(failureStrategy, subject);
check().that((Object) subject).named("Optional<T>").isNotNull();
}
内容来源于网络,如有侵权,请联系作者删除!