Package yalp.data.binding

Source Code of yalp.data.binding.BeanWrapperTest$Bean

package yalp.data.binding;

import org.junit.Test;
import yalp.YalpBuilder;
import yalp.data.validation.ValidationBuilder;

import java.util.HashMap;
import java.util.Map;

import static org.fest.assertions.Assertions.assertThat;

public class BeanWrapperTest {

    public static class Bean {
        public String a = "a";
        public String b = "b";
        public int i = 1;

        public String getA() {
            return a;
        }

        public void setA(String a) {
            this.a = a;
        }

        public String getB() {
            return b;
        }

        public void setB(String b) {
            this.b = b;
        }

        public int getI() {
            return i;
        }

        public void setI(int i) {
            this.i = i;
        }
    }

    @Test
    public void testBind() throws Exception {

        new YalpBuilder().build();
        ValidationBuilder.build();
        Map<String, String[]> m = new HashMap<String, String[]>();
        m.put("b.a", new String[]{"a1"});
        m.put("b.b", new String[]{"b1"});
        m.put("b.i", new String[]{"2"});

        Bean b = new Bean();
        new BeanWrapper(Bean.class).bind("b", null, m, "", b, null);
        assertThat(b.a).isEqualTo("a1");
        assertThat(b.b).isEqualTo("b1");
        assertThat(b.i).isEqualTo(2);

        b = new Bean();
        new BeanWrapper(Bean.class).bind("", null, m, "b", b, null);
        assertThat(b.a).isEqualTo("a1");
        assertThat(b.b).isEqualTo("b1");
        assertThat(b.i).isEqualTo(2);

        b = (Bean) new BeanWrapper(Bean.class).bind("b", null, m, "", null);
        assertThat(b.a).isEqualTo("a1");
        assertThat(b.b).isEqualTo("b1");
        assertThat(b.i).isEqualTo(2);


    }
}
TOP

Related Classes of yalp.data.binding.BeanWrapperTest$Bean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.