Closed bbcbruno closed 11 years ago
@BrunoBCampos Before you change the implementation, please merge with master because we had a lot of changes to support immutable objects.
@aparra @ahirata @BrunoBCampos I was thinking about this implementation, this is actually a random from a Enum. Isn't better to implement a random function that receives a quantity param and a Enum class?
Fixture.of(Empresa.class).addTemplate("valid", new Rule() {{ add("modalidades", random(Enum.class, 2)) }});
I think this is better DSL:
Fixture.of(Empresa.class).addTemplate("valid", new Rule() {{ add("modalidades", has(2).of(Enum.class)); }});
What do you think?
I was talking with @ahirata another day about this. The use of has function make it look better.
Maybe we can receive an additional varagrs with the Enum values that we want.
add("modalidades", has(2).of(Enum.class)); //return 2 random enum values add("modalidades", has(2).of(Enum.class, Enum.VALID)); //return 2 Enum.VALID add("modalidades", has(2).of(Enum.class, Enum.VALID, Enum.INVALID)); //return 2 Enum.VALID and Enum.INVALID add("modalidades", has(3).of(Enum.class, Enum.VALID, Enum.INVALID)); //throw IllegalArgumentException because the quantity and enum values quantity are not the same
I believe that function add("property", has(2).of(Enum.class)) will be more used. The other cases are unusual. Initially we´ll implement the first case. Then, if necessary, we´ll improve it.
What do you think?
Just like @aparra, i think add("property", has(2).of(Enum.class)) is better. All of other cases are necessary in too specific situations.
Ok.
@BrunoBCampos will you make this?
@nykolaslima it is already done unless you do want to change something.
@BrunoBCampos Did you make the changes that I suggest in the previous comment?
And merge your branch with master because we got a lot of changes.
@nykolaslima I will merge my branch with master but like I already said to you before, is not possible to change just like you said because FixtureFunction and ObjectFactory are not in the same package, so I can't use a protected method.
Any sugestion?
@BrunoBCampos maybe we can create a "gimme" method that only receives a quantity parameter and throws an IllegalArgumentException if the template class isn't Enum.
public List gimme(Integer quantity); { if(!templateHolder.getClazz().isEnum()) { throw new IllegalArgumentException("This method can only be used with Enum classes"); } ... }
What do you think @aparra and @BrunoBCampos ?
Something was lost along the way. We´ve talked about this feature:
Fixture.of(Empresa.class).addTemplate("valid", new Rule() {{ add("modalidades", has(2).of(Enum.class)); }});
This feature don't have side effects in ObjectFactory class, we only need to create a function that returns a List
The feature Fixture.from(Enum.class).gimme(xpto ...) is awkward.
Ok, i will solve this issue with other solution. Please close this PR.
Alteração para suportar listas de enums conforme issue #8.