There are two ways: The image and the rendering based one.
The image way: You must find a way to render the image to an internal pixel buffer (so you can run your tests "headless", i.e. without an actual UI popping up).
Then select a few pixels and make sure their colors are correct. In your example, select a couple of white pixels around the text to make sure the rendering doesn't leak. Helper methods like assertThatRectangleIs(area, color)
will help cover some ground. The idea is to select specific areas (like the left vertical bar of the H) and not be too picky.
The rendering based way works with the assumption that your gfx library works. So what you do is you mock the actual rendering code with something like this:
public class MockGC extends GC {
List<Op> ops = new ArrayList<Op> ();
void drawLine (int x1, int y1, int x2, int y2) {
ops.add(new Line(x1, y1, x2, y2, copyGC (gc)));
}
}
so you just save the command and all relevant options in a data structure that is easy to compare. Or even:
public class MockGC extends GC {
StringBuilder buffer = new StringBuilder ();
void drawLine (int x1, int y1, int x2, int y2) {
buffer.append("line "+x1+","+y1+" - "+x2+","+y2+", color="+foreground()+"\n");
}
}
Later, you can then just verify that the correct rendering commands have been issued and that the GC (colors, font, rendering hints) was used.
The latter way is much faster and 100% precise but much more work to code.