|
@ -0,0 +1,64 @@ |
|
|
|
|
|
package hs.fulda.de.ci.exam.project; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
|
|
import org.mockito.InjectMocks; |
|
|
|
|
|
import org.mockito.Mock; |
|
|
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
|
|
public class CustomerTest { |
|
|
|
|
|
|
|
|
|
|
|
final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); |
|
|
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
|
|
final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_setFlyingNumber() throws NoSuchFieldException, IllegalAccessException{ |
|
|
|
|
|
|
|
|
|
|
|
person1.setFrequentFlyerNumber("5"); |
|
|
|
|
|
|
|
|
|
|
|
final Field field = person1.getClass().getDeclaredField("frequentFlyerNumber"); |
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
assertEquals(field.get(person1), "5","set frequent flying number of the customer"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_getFlyingNumber() throws NoSuchFieldException, IllegalAccessException { |
|
|
|
|
|
|
|
|
|
|
|
final Field field = person1.getClass().getDeclaredField("frequentFlyerNumber"); |
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
field.set(person1, "10"); |
|
|
|
|
|
|
|
|
|
|
|
final String result = person1.getFrequentFlyerNumber(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(result, "10","get frequent flying number of the customer"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
private ItineraryRepository itineraryRepo; |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_getItineraries() { |
|
|
|
|
|
ArrayList<Itinerary> itineraries = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
Airport airport_fr = new Airport("Fraport", address1, "1234"); |
|
|
|
|
|
Airport airport_be = new Airport("Berlin", address1, "5678"); |
|
|
|
|
|
Itinerary item1 = new Itinerary(airport_fr, airport_be); |
|
|
|
|
|
Itinerary item2 = new Itinerary(airport_be, airport_fr); |
|
|
|
|
|
itineraries.add(item1); |
|
|
|
|
|
itineraries.add(item2); |
|
|
|
|
|
|
|
|
|
|
|
when(itineraryRepo.findAll()).thenReturn(itineraries); |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Itinerary> new_itineraries = person1.getItineraries(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(2, new_itineraries.size(), "Sizes are equal"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |