Skip to content

Commit

Permalink
Issue ota4j-team#21: Add test for DebuggableException
Browse files Browse the repository at this point in the history
* Refactored ExceptionTestHelper to provide better/easier to understand
  support for testing DebuggableExceptions.
* Introduces test for DebuggableException
* Renames methods of DebugInformation to be similar to Map interface.
  • Loading branch information
mmichaelis committed Jul 18, 2016
1 parent e9535ea commit d39d2a8
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 91 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/opentest4j/AssertionFailedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.opentest4j;

import static org.opentest4j.debug.DebugInformation.builder;
import static org.opentest4j.debug.DebugInformationDefaultKey.ACTUAL;
import static org.opentest4j.debug.DebugInformationDefaultKey.EXPECTED;
import static org.opentest4j.debug.DebugInformation.builder;

import org.opentest4j.debug.DebugInformation;
import org.opentest4j.debug.ValueDescriptor;
Expand Down Expand Up @@ -79,7 +79,7 @@ public AssertionFailedException(DebugInformation debugInformation, Throwable cau
*/
public AssertionFailedException(String message, Object expected, Object actual) {
this(message,
builder().addValue(EXPECTED.getId(), expected).addValue(ACTUAL.getId(), actual).build());
builder().put(EXPECTED.getId(), expected).put(ACTUAL.getId(), actual).build());
}

/**
Expand All @@ -94,7 +94,7 @@ public AssertionFailedException(String message, Throwable cause) {
*/
public AssertionFailedException(String message, Object expected, Object actual, Throwable cause) {
this(message,
builder().addValue(EXPECTED.getId(), expected).addValue(ACTUAL.getId(), actual).build(),
builder().put(EXPECTED.getId(), expected).put(ACTUAL.getId(), actual).build(),
cause);
}

Expand All @@ -104,7 +104,7 @@ public AssertionFailedException(String message, Object expected, Object actual,
* @see #getExpected()
*/
public boolean isExpectedDefined() {
return hasDebugInformation() && getDebugInformation().hasValue(EXPECTED.getId());
return hasDebugInformation() && getDebugInformation().containsKey(EXPECTED.getId());
}

/**
Expand All @@ -113,7 +113,7 @@ public boolean isExpectedDefined() {
* @see #getActual()
*/
public boolean isActualDefined() {
return hasDebugInformation() && getDebugInformation().hasValue(ACTUAL.getId());
return hasDebugInformation() && getDebugInformation().containsKey(ACTUAL.getId());
}

/**
Expand All @@ -122,7 +122,7 @@ public boolean isActualDefined() {
* @see #isExpectedDefined()
*/
public ValueDescriptor getExpected() {
return isExpectedDefined() ? getDebugInformation().getValue(EXPECTED.getId()) : null;
return isExpectedDefined() ? getDebugInformation().get(EXPECTED.getId()) : null;
}

/**
Expand All @@ -131,7 +131,7 @@ public ValueDescriptor getExpected() {
* @see #isActualDefined()
*/
public ValueDescriptor getActual() {
return isActualDefined() ? getDebugInformation().getValue(ACTUAL.getId()) : null;
return isActualDefined() ? getDebugInformation().get(ACTUAL.getId()) : null;
}

}
18 changes: 9 additions & 9 deletions src/main/java/org/opentest4j/debug/DebugInformation.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

package org.opentest4j.debug;

import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSet;

import java.io.Serializable;
import java.util.HashMap;
Expand Down Expand Up @@ -41,7 +41,7 @@ public class DebugInformation implements Serializable {
* @param values values; must be non-null
*/
private DebugInformation(Map<String, ValueDescriptor> values) {
this.values = unmodifiableMap(values);
this.values = new HashMap<String, ValueDescriptor>(values);
}

/**
Expand All @@ -58,19 +58,19 @@ public static DebugInformationBuilder builder() {
*
* @param key debug information key
* @return value descriptor or {@code null} iff. there is no debug information for the given key.
* @see #hasValue(String)
* @see #containsKey(String)
*/
public ValueDescriptor getValue(String key) {
public ValueDescriptor get(String key) {
return this.values.get(key);
}

/**
* Test if a value descriptor for the given debug information key exists.
*
* @param key debug information key
* @return true iff. {@link #getValue(String)} for the given return will return a value different to {@code null}
* @return true iff. {@link #get(String)} for the given return will return a value different to {@code null}
*/
public boolean hasValue(String key) {
public boolean containsKey(String key) {
return this.values.containsKey(key);
}

Expand All @@ -79,8 +79,8 @@ public boolean hasValue(String key) {
*
* @return value ids, non-null
*/
public Set<String> getValueIds() {
return this.values.keySet();
public Set<String> keySet() {
return unmodifiableSet(this.values.keySet());
}

/**
Expand All @@ -103,7 +103,7 @@ private DebugInformationBuilder() {
* @param object object, might be {@code null}
* @return self-reference
*/
public DebugInformationBuilder addValue(String key, Object object) {
public DebugInformationBuilder put(String key, Object object) {
this.values.put(key, ValueDescriptor.create(object));
return this;
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/opentest4j/DebuggableExceptionTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

package org.opentest4j;

import static org.opentest4j.ExceptionTestHelper.assertBehavesLikeStandardException;

import org.junit.Test;

/**
* Tests {@link DebuggableException}.
*
* @author Mark Michaelis
* @since 1.0
*/
public class DebuggableExceptionTests {
@Test
public void standardConstructorsHaveSameBehaviorAsJavaStandard() throws Exception {
assertBehavesLikeStandardException(DebuggableException.class);
}

@Test
public void debugInformationConstructorsBehaveAsExpected() throws Exception {
ExceptionTestHelper.assertBehavesLikeDebuggableException(DebuggableException.class);
}
}
Loading

0 comments on commit d39d2a8

Please sign in to comment.