I am finding some difficulties trying to implement a factory class in Java that build a RoomTipology object selecting a random value from an enum. So I have the following situation:
public class RoomTipologyMockFactory {
private RoomTipology roomTipology;
private static enum RoomTipologyEnum {
MATRIMONIALE,
MATRIMONILAE_SUPERIOR,
QUADRUPLA,
TRIPLA,
SINGOLA;
private static final List<RoomTipologyEnum> VALUES = Collections.unmodifiableList(Arrays.asList(values()));
private static final int SIZE = VALUES.size();
private static final Random RANDOM = new Random();
public static RoomTipologyEnum getRandomRoomTipologyValue() {
return VALUES.get(RANDOM.nextInt(SIZE));
}
}
public static RoomTipology getRandomRoomTipology() {
List<Object> value = RoomTipologyEnum.getRandomRoomTipology();
RoomTipology result = new RoomTipology();
switch (roomTipology) {
case MATRIMONIALE:
result.setName("Matrimoniale");
result.setDescription("Camera matrimoniale con bagno interno, Lorem ipsum dolor sit amet, consectetuer " +
"adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus " +
"et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, " +
"pellentesque eu, pretium quis, sem.");
result.setMaxPeople(2);
result.setTimeStamp(new Date());
break;
case MATRIMONILAE_SUPERIOR:
result.setName("Matrimoniale Superior");
result.setDescription("Camera con bagno dotata di piccolo angolo soggiorno completo di divano e " +
"scrivania, molto luminosa, pavimenti in parquet, riscaldamento e aria condizionata, " +
"armadio/guardaroba, TV a schermo piatto dotata di canali satellitari, connessione Wi-Fi " +
"gratuita, bollitore e selezione di tè e tisane.");
result.setMaxPeople(2);
result.setTimeStamp(new Date());
break;
case QUADRUPLA:
result.setName("Camera Quadruola");
result.setDescription("Camera per quattro persone con bagno interno, Lorem ipsum dolor sit amet, consectetuer " +
"adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus " +
"et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, " +
"pellentesque eu, pretium quis, sem.");
result.setMaxPeople(4);
result.setTimeStamp(new Date());
break;
case TRIPLA:
result.setName("Camera Tripla");
result.setDescription("Camera per tre persone con bagno interno, Lorem ipsum dolor sit amet, consectetuer " +
"adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus " +
"et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, " +
"pellentesque eu, pretium quis, sem.");
result.setMaxPeople(3);
result.setTimeStamp(new Date());
break;
case SINGOLA:
result.setName("Camera Singola");
result.setDescription("Camera singola persona con bagno interno, Lorem ipsum dolor sit amet, consectetuer " +
"adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus " +
"et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, " +
"pellentesque eu, pretium quis, sem.");
result.setMaxPeople(1);
result.setTimeStamp(new Date());
break;
}
return result;
}
}
As you can see in the previous code I have an external RoomTipologyMockFactory that is used to create mocks instances of the RoomTipology class.
Every time tht the getRandomRoomTipology() method is called have to be selected a random possible value of the RoomTipologyEnum enum and so it use it to build a specific mock of the RoomTipology class.
So, inside the enum definition, I have created the getRandomRoomTipologyValue() method that returns a random value form the enum
public static RoomTipologyEnum getRandomRoomTipologyValue() { return VALUES.get(RANDOM.nextInt(SIZE)); }
I have to use this value into the getRandomRoomTipology to return a specific RoomTipology mock instance.
I have 2 problems:
1) I have declared this enum as private static (so it is a class level and, in theory I have not to build it with new() because I take it from the current RoomTipologyMockFactory instance. But I can't do:
List<Object> value = RoomTipologyEnum.getRandomRoomTipology();
it seems that can't resolve to the getRandomRoomTipology() method.
2) I have no more to switch on the enum but I think on the returned value.
What is wrong? What am I missing? How can I fix this issue?