BAEL-3987 (#9139)
* BAEL-3987 - Cast an int to an enum value * refactoring * code refactored * BAEL-3987 - Updated code snippets * bAEL-3987 - Fixed indentation
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.inttoenum;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class IntToEnumUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenIntToEnumUsingValuesMethod_thenReturnEnumObject() {
|
||||
int timeToDeliveryForOrderedPizzaStatus = 5;
|
||||
PizzaStatus[] pizzaStatuses = PizzaStatus.values();
|
||||
PizzaStatus pizzaOrderedStatus = null;
|
||||
for (int pizzaStatusIndex = 0; pizzaStatusIndex < pizzaStatuses.length; pizzaStatusIndex++) {
|
||||
if (pizzaStatuses[pizzaStatusIndex].getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) {
|
||||
pizzaOrderedStatus = pizzaStatuses[pizzaStatusIndex];
|
||||
}
|
||||
}
|
||||
assertEquals(pizzaOrderedStatus, PizzaStatus.ORDERED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIntToEnumUsingMap_thenReturnEnumObject() {
|
||||
int timeToDeliveryForOrderedPizzaStatus = 5;
|
||||
assertEquals(PizzaStatus.castIntToEnum(timeToDeliveryForOrderedPizzaStatus), PizzaStatus.ORDERED);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user