use of com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog in project mobile-center-sdk-android by Microsoft.
the class HandledErrorTest method trackError.
@Test
public void trackError() {
startCrashes();
Crashes.trackError(EXCEPTION);
verify(mChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && EXCEPTION.getMessage() != null && EXCEPTION.getMessage().equals(((HandledErrorLog) item).getException().getMessage());
}
}), eq(mCrashes.getGroupName()), eq(DEFAULTS));
reset(mChannel);
Crashes.trackError(EXCEPTION, new HashMap<String, String>() {
{
put(null, null);
put("", null);
put(generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*'), null);
put("1", null);
}
}, null);
verify(mChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && EXCEPTION.getMessage() != null && EXCEPTION.getMessage().equals(((HandledErrorLog) item).getException().getMessage()) && ((HandledErrorLog) item).getProperties().size() == 0;
}
}), eq(mCrashes.getGroupName()), eq(DEFAULTS));
reset(mChannel);
Crashes.trackError(EXCEPTION, new HashMap<String, String>() {
{
for (int i = 0; i < 30; i++) {
put("valid" + i, "valid");
}
}
}, null);
verify(mChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && EXCEPTION.getMessage() != null && EXCEPTION.getMessage().equals(((HandledErrorLog) item).getException().getMessage()) && ((HandledErrorLog) item).getProperties().size() == 20;
}
}), eq(mCrashes.getGroupName()), eq(DEFAULTS));
reset(mChannel);
final String longerMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*');
Crashes.trackError(EXCEPTION, new HashMap<String, String>() {
{
put(longerMapItem, longerMapItem);
}
}, null);
verify(mChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof HandledErrorLog) {
HandledErrorLog errorLog = (HandledErrorLog) item;
if (EXCEPTION.getMessage() != null && EXCEPTION.getMessage().equals((errorLog.getException().getMessage()))) {
if (errorLog.getProperties().size() == 1) {
Map.Entry<String, String> entry = errorLog.getProperties().entrySet().iterator().next();
return entry.getKey().length() == ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH && entry.getValue().length() == ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH;
}
}
}
return false;
}
}), eq(mCrashes.getGroupName()), eq(DEFAULTS));
HandledErrorLog mockLog = mock(HandledErrorLog.class);
CrashesListener mockListener = mock(CrashesListener.class);
mCrashes.setInstanceListener(mockListener);
/* mCrashes callback test for trackError. */
mCrashes.getChannelListener().onBeforeSending(mockLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
mCrashes.getChannelListener().onSuccess(mockLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
mCrashes.getChannelListener().onFailure(mockLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
ErrorAttachmentLog attachmentLog = mock(ErrorAttachmentLog.class);
mCrashes.getChannelListener().onBeforeSending(attachmentLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
mCrashes.getChannelListener().onSuccess(attachmentLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
mCrashes.getChannelListener().onFailure(attachmentLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
}
Aggregations