Europe: +41 78 715 83 09 - Asia: +84 ‎975 112 112


7 Feb 2012

Vaadin and Groovy Test 4


TDD for Story 1
Now we have wrote the TA for the first Story, we can start on the TDD.
I create a class call VaadinCalculatorTest

import org.junit.Test
import org.junit.Before
import org.junit.After
import com.vaadin.ui.Button
import static org.mockito.Mockito.*

class VaadinCalculatorTest {

private VaadinCalculator calculator

@Before void before() {
calculator = new VaadinCalculator()

@After void after() {

@Test void shouldDisplay2IfIPressButton2() {
def event = mock(Button.ClickEvent)
def button = mock(Button)



assert calculator.result == VaadinCalculator.TWO



The first thing, we need to verify it’s if press button “2”, it’s what we pressed. It’s quite similar to our VaadinCalculatorSpec. If we run now, the compilation  work but the test fail. We need to implement the VaadinCalculator so the test run green.

import com.vaadin.Application
import com.vaadin.ui.Button

class VaadinCalculator extends Application implements Button.ClickListener{

static String TWO = "2"
String result = 6

def void init() {


def void buttonClick(Button.ClickEvent clickEvent) {
def button = clickEvent.button
result = button.caption

For the readers who don’t use TDD, it’s quite strange to implement only the button “2” and not all the button. But we will by the time we have tested all the button. If we run the current test, now the test, it’s green.

On line 17th and 18th, we have all the properties needed to catch the information needed. Exactly now, the page display nothing. But the event work perfectly.

Leave a Reply

Translate »