本文整理了Java中java.lang.AssertionError.setStackTrace()
方法的一些代码示例,展示了AssertionError.setStackTrace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AssertionError.setStackTrace()
方法的具体详情如下:
包路径:java.lang.AssertionError
类名称:AssertionError
方法名:setStackTrace
暂无
代码示例来源:origin: spring-projects/spring-framework
private static AssertionError createLeakError(DataBuffer delegate) {
String message = String.format("DataBuffer leak detected: {%s} has not been released.%n" +
"Stack trace of buffer allocation statement follows:",
delegate);
AssertionError result = new AssertionError(message);
// remove first four irrelevant stack trace elements
StackTraceElement[] oldTrace = result.getStackTrace();
StackTraceElement[] newTrace = new StackTraceElement[oldTrace.length - 4];
System.arraycopy(oldTrace, 4, newTrace, 0, oldTrace.length - 4);
result.setStackTrace(newTrace);
return result;
}
代码示例来源:origin: org.mockito/mockito-core
/**
* Creates a copy of the given assertion error with the custom failure message prepended.
* @param error The assertion error to copy
* @param message The custom message to prepend
* @since 2.1.0
*/
public MockitoAssertionError(MockitoAssertionError error, String message) {
super(message + "\n" + error.getMessage());
super.setStackTrace(error.getStackTrace());
unfilteredStackTrace = error.getUnfilteredStackTrace();
}
代码示例来源:origin: immutables/immutables
static void fail(@Nullable Object actualValue, Matcher<?> matcher) {
Description description =
new StringDescription()
.appendText("\nExpected: ")
.appendDescriptionOf(matcher)
.appendText("\n but: ");
matcher.describeMismatch(actualValue, description);
AssertionError assertionError = new AssertionError(description.toString());
assertionError.setStackTrace(ObjectChecker.trimStackTrace(assertionError.getStackTrace()));
throw assertionError;
}
代码示例来源:origin: org.assertj/assertj-core
private void removeCustomAssertRelatedElementsFromStackTraceIfNeeded(AssertionError assertionError) {
if (!Failures.instance().isRemoveAssertJRelatedElementsFromStackTrace()) return;
if (isAssertjAssertClass()) return;
StackTraceElement[] newStackTrace = Arrays.stream(assertionError.getStackTrace())
.filter(element -> !isElementOfCustomAssert(element))
.toArray(StackTraceElement[]::new);
assertionError.setStackTrace(newStackTrace);
}
代码示例来源:origin: joel-costigliola/assertj-core
private void removeCustomAssertRelatedElementsFromStackTraceIfNeeded(AssertionError assertionError) {
if (!Failures.instance().isRemoveAssertJRelatedElementsFromStackTrace()) return;
if (isAssertjAssertClass()) return;
StackTraceElement[] newStackTrace = Arrays.stream(assertionError.getStackTrace())
.filter(element -> !isElementOfCustomAssert(element))
.toArray(StackTraceElement[]::new);
assertionError.setStackTrace(newStackTrace);
}
代码示例来源:origin: neo4j/neo4j
@Override
public T apply( GraphDatabaseService graphDb )
{
try
{
return perform( graphDb );
}
catch ( AssertionError e )
{
AssertionError error = new AssertionError( message + ": " + e.getMessage() );
error.setStackTrace( e.getStackTrace() );
throw error;
}
}
代码示例来源:origin: goldmansachs/gs-collections
StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop];
System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length);
e.setStackTrace(newStackTrace);
throw e;
代码示例来源:origin: eclipse/eclipse-collections
StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop];
System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length);
e.setStackTrace(newStackTrace);
throw e;
代码示例来源:origin: pholser/junit-quickcheck
originalFailure);
e.setStackTrace(smallerFailure.getStackTrace());
return e;
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
public AssertionError wrap(String message) {
String outputMessage =
(this.message == null || this.message.isEmpty())
? message
: (this.message + ": " + message);
AssertionError res = new AssertionError(outputMessage);
res.setStackTrace(creationStackTrace);
return res;
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
public AssertionError wrap(Throwable t) {
AssertionError res =
new AssertionError(
message.isEmpty() ? t.getMessage() : (message + ": " + t.getMessage()), t);
res.setStackTrace(creationStackTrace);
return res;
}
代码示例来源:origin: net.java.quickcheck/quickcheck
@Override public void evaluate() throws Throwable {
try {
base.evaluate();
} catch(Throwable e) {
String message = e.getMessage() == null ? "" : e.getMessage();
AssertionError error = new AssertionError(format("%s (Seed was %sL.)", message, seed));
error.setStackTrace(e.getStackTrace());
throw error;
}
}
};
代码示例来源:origin: org.echocat.jomon/testing
public static void fail(@Nullable String message) {
final AssertionError error = message != null ? new AssertionError(message) : new AssertionError();
error.setStackTrace(getCleanStackTrace());
throw error;
}
代码示例来源:origin: net.peachjean.commons/pjcommons-test
private AssertionError generateError(final List<AssertionError> assertionErrors)
{
AssertionError error = new AssertionError(joinMessages(assertionErrors));
List<StackTraceElement> allElements = Lists.newArrayList();
for (AssertionError assertionError : assertionErrors)
{
allElements.addAll(Arrays.asList(assertionError.getStackTrace()));
}
error.setStackTrace(allElements.toArray(new StackTraceElement[allElements.size()]));
return error;
}
代码示例来源:origin: org.patterntesting/patterntesting-rt
/**
* Assert that all connections are closed.
*/
public static void assertConnectionsClosed() {
int count = INSTANCE.getOpenConnections();
if (count > 0) {
AssertionError error = new AssertionError(count + " connection(s) not closed");
error.setStackTrace(openConnections.iterator().next().getCaller());
throw error;
}
}
代码示例来源:origin: org.unitils/unitils-mock
public void assertNoMoreInvocations(StackTraceElement[] assertedAt) {
List<ObservedInvocation> unexpectedInvocations = new ArrayList<ObservedInvocation>();
for (int i = 0; i < observedInvocations.size(); i++) {
ObservedInvocation observedInvocation = observedInvocations.get(i);
VerificationStatus invocationVerificationStatus = invocationVerificationStatuses.get(i);
if (observedInvocation.getMockBehavior() == null && invocationVerificationStatus == UNVERIFIED) {
unexpectedInvocations.add(observedInvocation);
}
}
if (unexpectedInvocations.size() != 0) {
AssertionError assertionError = new AssertionError(getNoMoreInvocationsErrorMessage(unexpectedInvocations, assertedAt[0]));
assertionError.setStackTrace(assertedAt);
throw assertionError;
}
}
代码示例来源:origin: sebastianbenz/Jnario
private AssertionError newAssertionError(RowResults results) {
AssertionError error = new AssertionError(createMessage(results));
error.setStackTrace(results.getStackTrace());
return error;
}
代码示例来源:origin: org.unitils/unitils-mock
public void assertNotInvoked(BehaviorDefiningInvocation assertInvocation) {
for (int i = 0; i < observedInvocations.size(); i++) {
ObservedInvocation observedInvocation = observedInvocations.get(i);
VerificationStatus invocationVerificationStatus = invocationVerificationStatuses.get(i);
if (invocationVerificationStatus == UNVERIFIED && assertInvocation.matches(observedInvocation) != -1) {
AssertionError assertionError = new AssertionError(getAssertNotInvokedErrorMessage(assertInvocation, observedInvocation, assertInvocation.getInvokedAtTrace()));
assertionError.setStackTrace(assertInvocation.getInvokedAtTrace());
throw assertionError;
}
}
}
代码示例来源:origin: org.unitils/unitils-mock
public void assertInvoked(BehaviorDefiningInvocation assertInvocation) {
for (int i = 0; i < observedInvocations.size(); i++) {
ObservedInvocation observedInvocation = observedInvocations.get(i);
VerificationStatus invocationVerificationStatus = invocationVerificationStatuses.get(i);
if (invocationVerificationStatus == UNVERIFIED && assertInvocation.matches(observedInvocation) != -1) {
// Found a match that's not verified yet. Mark as verified and proceed.
invocationVerificationStatuses.set(i, VERIFIED);
return;
}
}
AssertionError assertionError = new AssertionError(getAssertInvokedErrorMessage(assertInvocation, assertInvocation.getInvokedAt()));
assertionError.setStackTrace(assertInvocation.getInvokedAtTrace());
throw assertionError;
}
代码示例来源:origin: org.dspace.dependencies.jmockit/dspace-jmockit
@Override
public final void setCustomErrorMessage(CharSequence customMessage)
{
Expectation expectation = getCurrentExpectation();
if (pendingError == null) {
expectation.setCustomErrorMessage(customMessage);
}
else if (customMessage != null) {
StackTraceElement[] previousStackTrace = pendingError.getStackTrace();
pendingError = new AssertionError(customMessage + "\n" + pendingError.getMessage());
pendingError.setStackTrace(previousStackTrace);
}
}
内容来源于网络,如有侵权,请联系作者删除!