本文整理了Java中com.google.common.truth.ThrowableSubject.hasMessage()
方法的一些代码示例,展示了ThrowableSubject.hasMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThrowableSubject.hasMessage()
方法的具体详情如下:
包路径:com.google.common.truth.ThrowableSubject
类名称:ThrowableSubject
方法名:hasMessage
[英]Fails if the subject does not have the given message.
[中]如果主题没有给定的消息,则失败。
代码示例来源:origin: robolectric/robolectric
@Test
public void testReadWithoutRewinding() {
parcel.writeInt(123);
try {
parcel.readInt();
fail("should have thrown");
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Did you forget to setDataPosition(0) before reading the parcel?");
}
}
代码示例来源:origin: JakeWharton/butterknife
@Test public void finderThrowsNiceError() {
Context context = InstrumentationRegistry.getContext();
View view = new View(context);
try {
Utils.findRequiredView(view, android.R.id.button1, "yo mama");
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Required view 'button1' with ID "
+ android.R.id.button1
+ " for yo mama was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testInvalidReadFromMiddleOfObject() {
parcel.writeLong(111L);
parcel.writeLong(222L);
parcel.setDataPosition(0);
parcel.setDataPosition(4);
try {
parcel.readInt();
fail("should have thrown UnreliableBehaviorError");
} catch (UnreliableBehaviorError e) {
assertThat(e)
.hasMessage(
"Looking for Integer at position 4, found Long [111] taking 8 bytes, but "
+ "[222] interrupts it at position 8");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testInvalidReadFromOverwrittenObject() {
parcel.writeString("hello all");
parcel.setDataPosition(4);
parcel.writeInt(5);
parcel.setDataPosition(0);
try {
parcel.readString();
fail("should have thrown UnreliableBehaviorError");
} catch (UnreliableBehaviorError e) {
assertThat(e)
.hasMessage(
"Looking for String at position 0, found String [hello all] taking 24 bytes, but "
+ "[5] interrupts it at position 4");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndReadByteArray_justLengthButNoContents() {
parcel.writeInt(3);
parcel.setDataPosition(0);
try {
parcel.createByteArray();
fail("expected exception");
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Byte array's length prefix is 3 but real length is 0");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testMarshallFailsFastReadingInterruptedObject() {
parcel.writeString("hello all");
parcel.setDataPosition(4);
parcel.writeInt(1);
try {
parcel.marshall();
fail();
} catch (UnreliableBehaviorError e) {
assertThat(e)
.hasMessage(
"Looking for Object at position 0, found String [hello all] taking 24 bytes, but "
+ "[1] interrupts it at position 4");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteStringReadInt() {
String val = "test";
parcel.writeString(val);
parcel.setDataPosition(0);
try {
parcel.readInt();
fail("should have thrown");
} catch (RuntimeException e) {
assertThat(e)
.hasCauseThat()
.hasMessage(
"Looking for Integer at position 0, found String [test] taking 16 bytes, "
+ "and it is non-portable to reinterpret it");
}
}
代码示例来源:origin: square/sqlbrite
@Test public void mapToOneOrDefaultDisallowsNullDefault() {
try {
Query.mapToOneOrDefault(MAPPER, null);
fail();
} catch (NullPointerException e) {
assertThat(e).hasMessage("defaultValue == null");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteIntReadString() {
int val = 9;
parcel.writeInt(val);
parcel.setDataPosition(0);
try {
parcel.readString();
fail("should have thrown");
} catch (RuntimeException e) {
assertThat(e)
.hasCauseThat()
.hasMessage(
"Looking for String at position 0, found Integer [9] taking 4 bytes, "
+ "and it is non-portable to reinterpret it");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testMarshallFailsFastReadingTruncatedObject() {
parcel.writeString("hello all");
parcel.setDataSize(8);
try {
parcel.marshall();
fail();
} catch (UnreliableBehaviorError e) {
assertThat(e)
.hasMessage(
"Looking for Object at position 0, found String [hello all] taking 24 bytes, but "
+ "[uninitialized data or the end of the buffer] interrupts it at position 8");
}
}
代码示例来源:origin: JakeWharton/butterknife
@Test public void finderThrowsLessNiceErrorInEditMode() {
Context context = InstrumentationRegistry.getContext();
View view = new EditModeView(context);
try {
Utils.findRequiredView(view, android.R.id.button1, "yo mama");
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Required view '<unavailable while editing>' "
+ "with ID " + android.R.id.button1
+ " for yo mama was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.");
}
}
代码示例来源:origin: square/sqlbrite
@Test public void builderDisallowsNull() {
SqlBrite.Builder builder = new SqlBrite.Builder();
try {
builder.logger(null);
fail();
} catch (NullPointerException e) {
assertThat(e).hasMessage("logger == null");
}
try {
builder.queryTransformer(null);
fail();
} catch (NullPointerException e) {
assertThat(e).hasMessage("queryTransformer == null");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testInvalidReadFromTruncatedObjectEvenAfterBufferRegrows() {
parcel.writeString("hello all");
parcel.setDataSize(12);
// Restore the original size, but the data should be lost.
parcel.setDataSize(100);
parcel.setDataPosition(0);
try {
parcel.readString();
fail("should have thrown UnreliableBehaviorError");
} catch (UnreliableBehaviorError e) {
assertThat(e)
.hasMessage(
"Looking for String at position 0, found String [hello all] taking 24 bytes, but "
+ "[uninitialized data or the end of the buffer] interrupts it at position 12");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testInvalidReadFromUninitializedData() {
// Write two longs with an 8-byte gap in the middle:
parcel.writeLong(333L);
parcel.setDataSize(parcel.dataSize() + 8);
parcel.setDataPosition(parcel.dataSize());
parcel.writeLong(444L);
parcel.setDataPosition(0);
assertThat(parcel.readLong()).isEqualTo(333L);
try {
parcel.readLong();
fail("should have thrown UnreliableBehaviorError");
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Reading uninitialized data at position 8");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testMarshallFailsFastReadingUninitializedData() {
parcel.writeString("hello everyone");
parcel.setDataSize(parcel.dataSize() + 4);
parcel.setDataPosition(parcel.dataSize());
parcel.writeInt(1);
try {
parcel.marshall();
fail();
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Reading uninitialized data at position 36");
}
}
代码示例来源:origin: square/sqlbrite
@Test public void callingEndMultipleTimesThrows() {
Transaction transaction = db.newTransaction();
transaction.end();
try {
transaction.end();
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Not in transaction.");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndReadByteArray_overwrittenLength() {
byte[] bytes = new byte[] {-1, 2, 3, 127};
parcel.writeByteArray(bytes);
assertThat(parcel.dataSize()).isEqualTo(8);
parcel.setDataPosition(0);
parcel.writeInt(3);
parcel.setDataPosition(0);
try {
parcel.createByteArray();
fail("expected exception");
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Byte array's length prefix is 3 but real length is 4");
}
}
代码示例来源:origin: apollographql/apollo-android
@Test public void duplicateSubscriptions() {
SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback1 = new SubscriptionManagerCallbackAdapter<>();
subscriptionManager.subscribe(subscription1, subscriptionManagerCallback1);
SubscriptionManagerCallbackAdapter<Operation.Data> subscriptionManagerCallback2 = new SubscriptionManagerCallbackAdapter<>();
subscriptionManager.subscribe(subscription1, subscriptionManagerCallback2);
assertThat(subscriptionManagerCallback2.error).hasMessage("Already subscribed");
}
代码示例来源:origin: square/sqlbrite
@Test public void mapToOneThrowsOnMultipleRows() {
Observable<Employee> employees =
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 2") //
.lift(Query.mapToOne(MAPPER));
try {
employees.blockingFirst();
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Cursor returned more than 1 row");
}
}
代码示例来源:origin: square/sqlbrite
@Test public void mapToOneOrDefaultThrowsOnMultipleRows() {
Observable<Employee> employees =
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 2") //
.lift(Query.mapToOneOrDefault(
MAPPER, new Employee("fred", "Fred Frederson")));
try {
employees.blockingFirst();
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Cursor returned more than 1 row");
}
}
内容来源于网络,如有侵权,请联系作者删除!