Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample 2nd commit #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added cherry.txt
Empty file.
19 changes: 16 additions & 3 deletions src/main/java/com/squareup/squash/SquashEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public class SquashEntry {
final String message;
final String log_message;

public SquashEntry(String client, String apiKey, String message, Throwable error,
public SquashEntry(String client, String apiKey, String logMessage, Throwable error,
String appVersion, int versionCode, String buildSha, String deviceId, String endpoint,
String userId, String environment) {
this.client = client;
this.log_message = message;
this.log_message = logMessage;
this.version = appVersion;
this.revision = buildSha;
this.build = "" + versionCode;
Expand All @@ -68,9 +68,22 @@ public SquashEntry(String client, String apiKey, String message, Throwable error
SquashBacktrace.populateNestedExceptions(parent_exceptions, error);
this.ivars = SquashBacktrace.getIvars(error);
this.class_name = error == null ? null : error.getClass().getName();
this.message = error == null ? null : error.getMessage();
this.message = createMessage(error, logMessage);
this.api_key = apiKey;
this.user_id = userId;
this.occurred_at = DATE_FORMAT_THREAD_LOCAL.get().format(new Date());
}

// Squash requires a non-empty message field.
private static String createMessage(Throwable error, String logMessage) {
String message;
if (error != null && error.getMessage() != null) {
message = error.getMessage();
} else if (logMessage != null) {
message = logMessage;
} else {
message = "No message";
}
return message;
}
}
35 changes: 35 additions & 0 deletions src/test/java/com/squareup/squash/SquashEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ private SquashEntry serializeAndDeserialize(SquashEntry logEntry) throws IOExcep
assertThat(deserialized.class_name).isEqualTo(exception.getClass().getName());
}

@Test public void testExceptionWithNoMessage() throws Exception {
final Throwable exception = mock(Throwable.class);

StackTraceElement s0 = new StackTraceElement("com.jake", "CantProgram",
"core-android/src/com/jake/Brain.java", 50);
StackTraceElement s1 = new StackTraceElement("com.jake", "IsDrunk",
"core-android/src/com/jake/Status.java", 510);
StackTraceElement[] stackTrace = { s0, s1 };

when(exception.getMessage()).thenReturn(null);
when(exception.getStackTrace()).thenReturn(stackTrace);

String logMessage = "Jake can't program";
final SquashEntry logEntry = factory.create(logMessage, exception);
SquashEntry deserialized = serializeAndDeserialize(logEntry);
assertThat(deserialized.message).isEqualTo(logMessage);
}

@Test public void testExceptionWithNoMessageOrLogMessage() throws Exception {
final Throwable exception = mock(Throwable.class);

StackTraceElement s0 = new StackTraceElement("com.jake", "CantProgram",
"core-android/src/com/jake/Brain.java", 50);
StackTraceElement s1 = new StackTraceElement("com.jake", "IsDrunk",
"core-android/src/com/jake/Status.java", 510);
StackTraceElement[] stackTrace = { s0, s1 };

when(exception.getMessage()).thenReturn(null);
when(exception.getStackTrace()).thenReturn(stackTrace);

final SquashEntry logEntry = factory.create(null, exception);
SquashEntry deserialized = serializeAndDeserialize(logEntry);
assertThat(deserialized.message).isEqualTo("No message");
}

private void assertBacktracesMatch(StackTraceElement[] myLittleStackTrace,
List<SquashBacktrace.StackElement> stackElements) {
for (int i = 0, stackElementsSize = stackElements.size(); i < stackElementsSize; i++) {
Expand Down
3 changes: 3 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
this is our 3rd class on git
git is version control tool