O'Reilly logo

Vaadin 7 Cookbook by Ondrej Kvasnovsky, Jaroslav Holan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The basics of mocking in Vaadin

In this recipe, we will show how to write a test for code which is not designed for easy unit testing. For example, we are forced to use an external class, which contains only a static method returning the status of a system. We just return a plain and hardcoded string "Online" in this example. But the class could, for example, return a status of a system, which is fetched from a web service.

public class SystemStatusService {

    public static String getValue() {
        return "Offline";
    }
}

We create a horizontal layout on which we place a label that contains a system status we get from the service:

public class SystemStatusLayout extends HorizontalLayout { private Label lblSystemStatus; public SystemStatusLayout() { String ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required