|
@ -1,27 +1,41 @@ |
|
|
package hs.fulda.de.ci.exam.project; |
|
|
package hs.fulda.de.ci.exam.project; |
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
import org.junit.Before; |
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
import org.mockito.InjectMocks; |
|
|
import org.mockito.InjectMocks; |
|
|
import org.mockito.Mock; |
|
|
import org.mockito.Mock; |
|
|
import org.mockito.MockitoAnnotations; |
|
|
import org.mockito.MockitoAnnotations; |
|
|
|
|
|
import org.mockito.invocation.InvocationOnMock; |
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
import org.mockito.stubbing.Answer; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.is; |
|
|
|
|
|
import static org.hamcrest.CoreMatchers.notNullValue; |
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.Mockito.when; |
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
@ExtendWith(MockitoExtension.class) |
|
|
public class AdminTest { |
|
|
public class AdminTest { |
|
|
|
|
|
|
|
|
final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); |
|
|
|
|
|
|
|
|
Address address_fr; |
|
|
|
|
|
Airport airport_fr; |
|
|
|
|
|
Address address1_ist; |
|
|
|
|
|
Airport airport1_ist; |
|
|
|
|
|
Flight flight1; |
|
|
|
|
|
Address address1; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
|
|
public void setup() { |
|
|
|
|
|
address_fr = new Address("Frankfurt str", "Frankfurt", "Hessen", "63023", "Germany"); |
|
|
|
|
|
airport_fr = new Airport("Fraport", address_fr, "1234"); |
|
|
|
|
|
address1_ist = new Address("Istanbul str", "Istanbul", "Fatih", "9019", "Turkey"); |
|
|
|
|
|
airport1_ist = new Airport("Istanbul", address1_ist, "5678"); |
|
|
|
|
|
flight1 = new Flight("1", airport_fr, airport1_ist, 140); |
|
|
|
|
|
address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); |
|
|
|
|
|
} |
|
|
@InjectMocks |
|
|
@InjectMocks |
|
|
Admin admin = new Admin("Max Muster", address1, "example@gmail.com", "012345678" ); |
|
|
Admin admin = new Admin("Max Muster", address1, "example@gmail.com", "012345678" ); |
|
|
|
|
|
|
|
@ -49,11 +63,6 @@ public class AdminTest { |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void test_addFlight_returnsNewFlight() throws IOException { |
|
|
public void test_addFlight_returnsNewFlight() throws IOException { |
|
|
Address address_fr = new Address("Frankfurt str", "Frankfurt", "Hessen", "63023", "Germany"); |
|
|
|
|
|
Airport airport_fr = new Airport("Fraport", address_fr, "1234"); |
|
|
|
|
|
Address address1_ist = new Address("Istanbul str", "Istanbul", "Fatih", "9019", "Turkey"); |
|
|
|
|
|
Airport airport1_ist = new Airport("Istanbul", address1_ist, "5678"); |
|
|
|
|
|
Flight flight1 = new Flight("1", airport_fr, airport1_ist, 140); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
when(flightRepository.save(any(Flight.class))).thenReturn(true); |
|
|
when(flightRepository.save(any(Flight.class))).thenReturn(true); |
|
@ -68,4 +77,15 @@ public class AdminTest { |
|
|
} |
|
|
} |
|
|
assertNotNull(admin.addFlight("1", airport_fr, airport1_ist, 140)); |
|
|
assertNotNull(admin.addFlight("1", airport_fr, airport1_ist, 140)); |
|
|
} |
|
|
} |
|
|
|
|
|
@Test |
|
|
|
|
|
public void testAddFlight_throwsException() throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
when(flightRepository.save(any(Flight.class))).thenThrow(IOException.class); |
|
|
|
|
|
assertThrows(IOException.class, () -> { |
|
|
|
|
|
admin.addFlight("1", airport_fr, airport1_ist, 140); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |