Book Image

Vaadin 7 Cookbook

Book Image

Vaadin 7 Cookbook

Overview of this book

Table of Contents (19 chapters)
Vaadin 7 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 value = SystemStatusService.getValue();
        lblSystemStatus = new Label(value);
        addComponent(lblSystemStatus);
    }

    public Label getLblSystemStatus() {
        return lblSystemStatus;
    }
}

Some...