Could you write a Unit-Test that checks and validates the correctness of this method (by trying all valid variants and some invalid variants) ?

I'm not 100% sure but are you certain that you have to use Strings to store the type of the elements?
I guess you could probably also do it by making the `type` variable a `Class` reference.