本文整理了Java中com.google.common.truth.ThrowableSubject.hasMessageThat()
方法的一些代码示例,展示了ThrowableSubject.hasMessageThat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThrowableSubject.hasMessageThat()
方法的具体详情如下:
包路径:com.google.common.truth.ThrowableSubject
类名称:ThrowableSubject
方法名:hasMessageThat
[英]Returns a StringSubject to make assertions about the throwable's message.
[中]
代码示例来源:origin: google/guava
public void testCheckArgument_tooManyArgs_failure() {
try {
Preconditions.checkArgument(false, "A %s C %s E", "b", "d", "f");
fail("no exception thrown");
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().isEqualTo("A b C d E [f]");
}
}
代码示例来源:origin: google/guava
public void testCheckState_nullMessage_failure() {
try {
Preconditions.checkState(false, null);
fail("no exception thrown");
} catch (IllegalStateException expected) {
assertThat(expected).hasMessageThat().isEqualTo("null");
}
}
代码示例来源:origin: google/guava
public void testCheckArgument_nullMessageWithArgs_failure() {
try {
Preconditions.checkArgument(false, null, "b", "d");
fail("no exception thrown");
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().isEqualTo("null [b, d]");
}
}
代码示例来源:origin: google/guava
public void testCheckArgument_nullArgs_failure() {
try {
Preconditions.checkArgument(false, "A %s C %s E", null, null);
fail("no exception thrown");
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().isEqualTo("A null C null E");
}
}
代码示例来源:origin: google/guava
public void testGetOnlyElement_withDefault_two() {
Iterator<String> iterator = asList("foo", "bar").iterator();
try {
Iterators.getOnlyElement(iterator, "x");
fail();
} catch (IllegalArgumentException expected) {
assertThat(expected).hasMessageThat().isEqualTo("expected one element but was: <foo, bar>");
}
}
代码示例来源:origin: google/guava
public void testReadLine() throws IOException {
DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data));
try {
in.readLine();
fail();
} catch (UnsupportedOperationException expected) {
assertThat(expected).hasMessageThat().isEqualTo("readLine is not supported");
}
}
代码示例来源:origin: google/guava
public void testLimit_markNotSet() {
byte[] big = newPreFilledByteArray(5);
InputStream bin = new ByteArrayInputStream(big);
InputStream lin = ByteStreams.limit(bin, 2);
try {
lin.reset();
fail();
} catch (IOException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Mark not set");
}
}
代码示例来源:origin: google/guava
public void testCheckElementIndex_withDesc_negative() {
try {
Preconditions.checkElementIndex(-1, 1, "foo");
fail();
} catch (IndexOutOfBoundsException expected) {
assertThat(expected).hasMessageThat().isEqualTo("foo (-1) must not be negative");
}
}
代码示例来源:origin: google/guava
private static void testEncodedLengthFails(String invalidString, int invalidCodePointIndex) {
try {
Utf8.encodedLength(invalidString);
fail();
} catch (IllegalArgumentException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo("Unpaired surrogate at index " + invalidCodePointIndex);
}
}
代码示例来源:origin: google/guava
public void testVerify_simpleMessage_failure() {
try {
verify(false, "message");
fail();
} catch (VerifyException expected) {
assertThat(expected).hasMessageThat().isEqualTo("message");
}
}
代码示例来源:origin: google/guava
public void testCheckPositionIndex_negative() {
try {
Preconditions.checkPositionIndex(-1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
assertThat(expected).hasMessageThat().isEqualTo("index (-1) must not be negative");
}
}
代码示例来源:origin: google/guava
public void testCheckPositionIndex_startNegative() {
try {
Preconditions.checkPositionIndexes(-1, 1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
assertThat(expected).hasMessageThat().isEqualTo("start index (-1) must not be negative");
}
}
代码示例来源:origin: google/guava
public void testRowPutIllegal() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Map<Integer, Character> map = table.row("foo");
try {
map.put(4, 'd');
fail();
} catch (IllegalArgumentException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Column 4 not in [1, 2, 3]");
}
}
代码示例来源:origin: google/guava
public void testGetCheckedUntimed_exceptionClassUsedInitCause() {
try {
getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, ExceptionWithoutThrowableConstructor.class);
fail();
} catch (ExceptionWithoutThrowableConstructor expected) {
assertThat(expected).hasMessageThat().contains("mymessage");
assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION);
}
}
代码示例来源:origin: google/guava
@Test
public void addEdge_orderMismatch() {
EndpointPair<Integer> endpoints = EndpointPair.unordered(N1, N2);
try {
addEdge(endpoints, E12);
fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
}
}
代码示例来源:origin: google/guava
public void testMarkNotSupported() {
counter = new CountingInputStream(new UnmarkableInputStream());
try {
counter.reset();
fail();
} catch (IOException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Mark not supported");
}
}
代码示例来源:origin: google/guava
@Test
public void edgeConnecting_orderMismatch() {
addEdge(N1, N2, E12);
try {
Optional<String> unused = network.edgeConnecting(EndpointPair.unordered(N1, N2));
fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
}
代码示例来源:origin: google/guava
@Test
public void edgeConnectingOrNull_orderMismatch() {
addEdge(N1, N2, E12);
try {
String unused = network.edgeConnectingOrNull(EndpointPair.unordered(N1, N2));
fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
}
代码示例来源:origin: google/guava
@Override
public void testNulls() throws Exception {
try {
super.testNulls();
} catch (AssertionFailedError e) {
assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
.that(e)
.hasCauseThat()
.hasMessageThat()
.contains(ERROR_ELEMENT_NOT_IN_GRAPH);
}
}
代码示例来源:origin: google/guava
@Test
public void putEdgeValue_directed_orderMismatch() {
graph = ValueGraphBuilder.directed().build();
try {
graph.putEdgeValue(EndpointPair.unordered(1, 2), "irrelevant");
fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
}
内容来源于网络,如有侵权,请联系作者删除!