exception filtering

3 views
Skip to first unread message

Ed

unread,
Nov 27, 2009, 9:42:45 AM11/27/09
to easytesting
Concersing latest version of FEST-Assert:

Might it be an idea to filter the org.fest eceptions in the
stacktrace ?
(just like for example testNG do).
I do this with my own exception helper classes and I find it very
friendly.

So instead of seeing this:
----
java.lang.AssertionError: expected:<'eeeee'> but was:<'eeeeeee'>
at org.fest.assertions.Fail.failure(Fail.java:206)
at org.fest.assertions.Fail.fail(Fail.java:196)
at org.fest.assertions.Fail.failWhenNotEqual(Fail.java:78)
at org.fest.assertions.Fail.failIfNotEqual(Fail.java:72)
at org.fest.assertions.GenericAssert.assertEqualTo(GenericAssert.java:
271)
at org.fest.assertions.StringAssert.isEqualTo(StringAssert.java:156)
at com.bv.declare.persinfo.PersInfoTest.testMemberName
(PersInfoTest.java:77)
---

I would this this:
----
java.lang.AssertionError: expected:<'eeeee'> but was:<'eeeeeee'>
at com.bv.declare.persinfo.PersInfoTest.testMemberName
(PersInfoTest.java:77)
----

How can I modify/configure FEST-Assertion to accomplish this?

Ed

unread,
Nov 27, 2009, 11:13:15 AM11/27/09
to easytesting
BTW: testNG does this by default.

Here a piece of my UtilsException class that I use to filter my
exceptions:

/**
* Will create a new stack for the specified exception that doesn't
contain any stacktrace element with a class
* name that starts with the specified reference (case sensitive).
* @return same as input.
*/
public static Throwable filterStackTrace(final Throwable th, final
String ref) {
StackTraceElement[] trace = th.getStackTrace();
if (UtilsMisc.hasContent(trace)) {
int counter = 0;
// remove the entries that contain the reference.
for (int i = 0; i < trace.length; i++) {
if (trace[i].getClassName().startsWith(ref)) {
trace[i] = null;
counter++;
}
}

// create a new stack trace that doesn't contain the null entries.
StackTraceElement[] newTrace = new StackTraceElement[trace.length -
counter];
counter = 0;
for (StackTraceElement elem : trace) {
if (elem != null) {
newTrace[counter] = elem;
counter++;
}
}

th.setStackTrace(newTrace);
}
return th;
}

Ed

unread,
Nov 27, 2009, 11:28:03 AM11/27/09
to easytesting
What you could do...:
In your Fail class call this above filter method in:

public static AssertionError failure(String message) {
return new AssertionError(message);
}

So this would something like:

public static AssertionError failure(String message) {
return UtilsException.filterStackTrace(new AssertionError
(message), Fail.class.getPackage.getName());
}

And that's it.. :)...
You could even set a static variable that can be changed if people
don't want this behavior.
I think I am just a bit spoiled as I am not just to seeing unwanted
elements in my stacktrace :(

Ed

unread,
Nov 27, 2009, 11:51:32 AM11/27/09
to easytesting
Ok,

I just checked out your source and made the above changes and it works
fine...
I don't think it's necessary to submit a patch as the above change is
very simple.

Now I have you source, I am going to see if I can add another "simple"
change:
something like assertThat(obj).log(obj1, obj2, ....).isEqualTo(...)...

Why? For me it's important to log some additional information to be
able to reproduce the bug/failure..
You could use the Description() class for it, but I think that breaks
the user friendlyness of fest-api fluent api.
I don't like this:
assertThat(new MyDescription("message", obj).log(obj1,
obj2, ....)).isEqualTo(...)...



Alex Ruiz

unread,
Nov 27, 2009, 2:26:31 PM11/27/09
to easyt...@googlegroups.com
Thanks Ed! This feature will be available in our next release (1.3)...and thanks for filing the ticket! :)

I like logging feature. I saw there is another thread for it. I'll be reading after sending this message.

Cheers,
-Alex




--

You received this message because you are subscribed to the Google Groups "easytesting" group.
To post to this group, send email to easyt...@googlegroups.com.
To unsubscribe from this group, send email to easytesting...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/easytesting?hl=en.



Ed

unread,
Nov 27, 2009, 2:37:10 PM11/27/09
to easytesting
Hi Alex,

It makes my happy that you reply quickly and like the idea's.. :)
Reply all
Reply to author
Forward
0 new messages