Ninja-Squad / DbSetup

An API for populating a database in unit tests
http://dbsetup.ninja-squad.com/
212 stars 34 forks source link

Use object to generate insert instead of values #37

Closed PierreLeresteux closed 9 years ago

PierreLeresteux commented 9 years ago

I create a new method in the Insert builder to generate row using an object instead of giving a Map of list of values. I do this, because, I use a lot DbSetup, and sometimes I like to create object to have better assertions.

I do something like that now :

MyClass myClass = new MyClass().setA(1).setB("foo").setC(true);
...
Insert.insertInto("class")
.columns("a","b","c")
.values(myClass.getA(),myClass.getB(),myClass.getC())
.build();

Because in my assertions I can have this :

assertThat(objectReturnedUsingSelectInMyCode).isEqualTo(myClass);

I made this PR to have this :

MyClass myClass = new MyClass().setA(1).setB("foo").setC(true); 
...
Insert.insertInto("class")
.columns("a","b","c")
.object(myClass)
.build();
jnizet commented 9 years ago

I understand your motivation, but this would make DbSetup much more complex and would slowly change it to some kind of ORM, needing all kinds of choices to be made:

I'd prefer not to embed this in DbSetup. You could add a Map<String, Object> toDbSetupMap() method to your class and simply do

insertInto("class")
    .columns("a","b","c")
    .values(myClass.toDbSetupMap())
    .build();
PierreLeresteux commented 9 years ago

Hi and thanks for your reply ...

I understand your point of view and I'm agree, I'll try to use your recommandation. :v:

Have a nice day.