aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/ui/CustomFieldTest.java
blob: eba3a81ed50c46a7939ae9147b4e461a62622f25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.vaadin.ui;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Iterator;
import java.util.NoSuchElementException;

import org.junit.Test;

public class CustomFieldTest {

    public static class TestCustomField extends CustomField<String> {

        private String value = "initial";
        private Button button;

        @Override
        public String getValue() {
            return value;
        }

        @Override
        protected Component initContent() {
            button = new Button("Content");
            return button;
        }

        @Override
        protected void doSetValue(String value) {
            this.value = value;

        }

    }

    @Test(expected = NoSuchElementException.class)
    public void iterator() {
        TestCustomField field = new TestCustomField();
        // Needs to trigger initContent somehow as
        // iterator() can't do it even though it should...
        field.getContent();
        Iterator<Component> iterator = field.iterator();
        assertNotNull(iterator);
        assertTrue(iterator.hasNext());
        assertEquals(field.button, iterator.next());
        assertFalse(iterator.hasNext());
        iterator.next();
    }
}