Skip to content

Commit

Permalink
Add an app error field to ProgramError.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Holmes committed Jan 3, 2015
1 parent 05d6106 commit 42d9214
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/com/dmdirc/logger/ErrorManager.java
Expand Up @@ -179,7 +179,7 @@ public void handleUserErrorEvent(final UserErrorEvent userError) {
protected ProgramError addError(final ErrorLevel level, final String message,
final Throwable exception, final String details, final boolean appError,
final boolean canReport) {
return addError(getError(level, message, exception, details), appError, canReport);
return addError(getError(level, message, exception, details, appError), appError, canReport);
}

protected ProgramError addError(
Expand Down Expand Up @@ -256,9 +256,9 @@ protected void addError(final ProgramError error) {
* @return A corresponding ProgramError
*/
protected ProgramError getError(final ErrorLevel level, final String message,
final Throwable exception, final String details) {
final Throwable exception, final String details, final boolean appError) {
return new ProgramError(level, message, exception, getTrace(message, exception), details,
new Date(), this, eventBus);
new Date(), this, eventBus, appError);
}

/**
Expand Down
15 changes: 14 additions & 1 deletion src/com/dmdirc/logger/ProgramError.java
Expand Up @@ -62,6 +62,8 @@ public class ProgramError implements Serializable {
private final ErrorManager errorManager;
/** The eventbus to post status changes to. */
private final DMDircMBassador eventBus;
/** Is this an application error? */
private final boolean appError;
/** Error report Status. */
private ErrorReportStatus reportStatus;
/** Has the error been output. */
Expand All @@ -84,7 +86,8 @@ public ProgramError(final ErrorLevel level, final String message,
@Nullable final String details,
final Date date,
final ErrorManager errorManager,
final DMDircMBassador eventBus) {
final DMDircMBassador eventBus,
final boolean appError) {
checkNotNull(level);
checkNotNull(message);
checkNotNull(date);
Expand All @@ -99,6 +102,7 @@ public ProgramError(final ErrorLevel level, final String message,
this.reportStatus = ErrorReportStatus.WAITING;
this.errorManager = errorManager;
this.eventBus = eventBus;
this.appError = appError;
}

/**
Expand Down Expand Up @@ -183,6 +187,15 @@ public boolean isHandled() {
return handled;
}

/**
* Is this an application error?
*
* @return true iif this is an application error
*/
public boolean isAppError() {
return appError;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
40 changes: 24 additions & 16 deletions test/com/dmdirc/logger/ProgramErrorTest.java
Expand Up @@ -55,46 +55,46 @@ public class ProgramErrorTest {
@Test(expected = NullPointerException.class)
public void testConstructorNullErrorLevel() {
new ProgramError(null, "moo", null, Lists.newArrayList(), null, new Date(), errorManager,
eventBus);
eventBus, true);
}

@Test(expected = NullPointerException.class)
public void testConstructorNullMessage() {
new ProgramError(ErrorLevel.HIGH, null, null, Lists.newArrayList(), null, new Date(),
errorManager, eventBus);
errorManager, eventBus, true);
}

@Test(expected = IllegalArgumentException.class)
public void testConstructorEmptyMessage() {
new ProgramError(ErrorLevel.HIGH, "", null, Lists.newArrayList(), null, new Date(),
errorManager, eventBus);
errorManager, eventBus, true);
}

@Test(expected = NullPointerException.class)
public void testConstructorNullDate() {
new ProgramError(ErrorLevel.HIGH, "moo", null, Lists.newArrayList(), null, null,
errorManager, eventBus);
errorManager, eventBus, true);
}

@Test
public void testConstructorGood() {
new ProgramError(ErrorLevel.HIGH, "moo", new UnsupportedOperationException(),
Lists.newArrayList(), null, new Date(), errorManager, eventBus);
Lists.newArrayList(), null, new Date(), errorManager, eventBus, true);
}

@Test
public void testGetLevel() {
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
errorManager, eventBus);
errorManager, eventBus, true);
assertEquals(ErrorLevel.HIGH, pe.getLevel());
}

@Test
public void testGetMessage() {
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
errorManager, eventBus);
errorManager, eventBus, true);
assertEquals("moo", pe.getMessage());
}

Expand All @@ -103,15 +103,23 @@ public void testGetDate() {
final Date date = new Date();
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), Lists.newArrayList(), null, date,
errorManager, eventBus);
errorManager, eventBus, true);
assertEquals(date, pe.getDate());
}

@Test
public void testIsAppError() {
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
errorManager, eventBus, true);
assertTrue(pe.isAppError());
}

@Test
public void testReportStatus() {
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
errorManager, eventBus);
errorManager, eventBus, true);
assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
pe.setReportStatus(null);
assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
Expand All @@ -129,7 +137,7 @@ public void testReportStatus() {
public void testToString() {
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), Lists.newArrayList(), null, new Date(),
errorManager, eventBus);
errorManager, eventBus, true);
assertTrue(pe.toString().contains("moo"));
}

Expand All @@ -138,23 +146,23 @@ public void testGetTrace() {
final List<String> trace = Lists.newArrayList("test", "test1", "test2");
final ProgramError pe = new ProgramError(ErrorLevel.HIGH, "moo",
new UnsupportedOperationException(), trace, null, new Date(), errorManager,
eventBus);
eventBus, true);
assertEquals(trace, pe.getTrace());
}

@Test
public void testEquals() {
final Exception ex = new UnsupportedOperationException();
final ProgramError pe1 = new ProgramError(ErrorLevel.LOW, "moo",
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus);
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true);
final ProgramError pe2 = new ProgramError(ErrorLevel.LOW, "moo",
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus);
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true);
final ProgramError pe3 = new ProgramError(ErrorLevel.MEDIUM, "moo",
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus);
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true);
final ProgramError pe4 = new ProgramError(ErrorLevel.LOW, "bar",
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus);
ex, Lists.newArrayList(), null, new Date(), errorManager, eventBus, true);
final ProgramError pe5 = new ProgramError(ErrorLevel.LOW, "moo",
null, Lists.newArrayList(), "Hello", new Date(), errorManager, eventBus);
null, Lists.newArrayList(), "Hello", new Date(), errorManager, eventBus, true);

assertFalse(pe1.equals(null)); // NOPMD
assertFalse(pe1.equals("moo"));
Expand Down

0 comments on commit 42d9214

Please sign in to comment.