six2six / fixture-factory

Generator fake objects from a template
Apache License 2.0
445 stars 88 forks source link

RandomPopFunction #43

Closed ghost closed 10 years ago

ghost commented 10 years ago

I've ended up creating a new class that implements AtomicFunction interface in order to be able to use a List as a stack of values for a unique property of my entity.

I think that this would be a good feature to be provided with the API. I also had to subclass Rule to provide 'public Function randomPop' that returns this RandomPopFunction.

nykolaslima commented 10 years ago

Can't you use RandomFunction?

add("name", random("nykolas", "maria", "joao");

ahirata commented 10 years ago

I'm late on this... but here's my 2 cents:

I don't see any problems in implementing custom AtomicFunctions when necessary. In fact, if you have some specific rule to generate your values, that's the way to go.

But you don't have to extend Rule to use your function. You can instantiate it directly:

add("someAttr", new RandomPopFunction())

It's more verbose but I think it's better than subclassing just to add a method to return that. Or You could create a static factory method...

Anyway, I didn't understand what your suggestion is. A function that'll use a stack or a function that'll generate unique values in a way that you won't need your function?

Maybe there is another way of doing that. Can you provide more information on how the values are? Are they sequencial numbers, randomly generated strings, etc? The uniqueness of the value is restricted to instances of a single class or it has to be unique among instances of different classes?

nykolaslima commented 10 years ago

@brunoskrebs can you share your function with us or can we close this?