Hellu again,
I am sorry for spaming your forum soo much from out of nothing :(...
Anyway: I looked at your as(..) method and would like to have it
extended (I added it to the issue tracker with a link to this post,
but I think it's good that people give their opinion before it's
implemented).
Before implementing it, you might first want to have a look at my
previous post about the Generics issue:
http://groups.google.com/group/easytesting/browse_thread/thread/898b9de8448c1b0e#
If that one is solved, this one is solved easy and fast as only small
modifications to the super class is needed.
I started making modifications to the current source, but it's a bit
too much to just do it quickly :(...
Anyway: I would love to extend the as(Description) method such that we
can easily submit objects that are logged in the error message.
This is possible through an Descriptor implementation, which is great
of course, but ti's not very user friendly.
In case of using the Description interface, you should get something
like this:
assertThat("bla").as(new ObjectsDescription("my objects", obj1, objs2,
objs3)).isEqualTo("bla1");
I am looking for something like this:
as(String message, String description1, Object obj1);
as(String message, String description1, Object obj1, String
description2, Object obj2);
as(String message, String description1, Object obj1, String
description2, Object obj2, String description3, Object obj3);
as(String message, String description1, Object obj1, String
description2, Object obj2, String description3, Object obj3, String
description4, Object obj4);
as(String message, Object...objs);
as(String message, String[] descriptions, Object...objs);
So the call would look for nice:
assertThat("bla").as("my objects", obj1, objs2, objs3).isEqualTo
("bla1");
This might not look as much of a "win" but if you do many of these
asserts, it will. Said that, the modifications are small and simple...
And I think you should hide the Presentation of the error message and
not mix them with any logic testing flow.... and repeat defining the
presentation again and again... I hope I got you confinced :)
So the output would be something like:
My error message:
Description1= ToString output of object1
Description2= ToString output of object2
Description3= ToString output of object3
...
Or if not descriptions are submitted:
My Error message:
obj-1= ToString output of object1
obj-2= ToString output of object2
obj-3= ToString output of object3
...
I would be nice to be able to set your own output formatter through a
constructor or static method....
I already made an ObjectsDescription, see below, but the as() method
changes results in a lot of modifications due to the lack of using the
Generics... so then I stopped :(.... I hope to get it will be
implemented soon...
----
public final class ObjectsDescription extends BasicDescription {
private final String[] descriptions;
private final Object[] objs;
public ObjectsDescription(String message, String[] descriptions,
Object[] objs) {
super(message);
this.descriptions = descriptions;
this.objs = objs;
}
@Override
public String value() {
return UtilsString.createLogString(super.value(), descriptions,
objs).toString();
}