Browse Source

add aircraft as an admin

feature-pr-Admin
Sona Markosyan 3 years ago
parent
commit
02dce958b4
  1. 10
      src/main/java/hs/fulda/de/ci/exam/project/Admin.java
  2. 5
      src/main/java/hs/fulda/de/ci/exam/project/Aircraft.java
  3. 22
      src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java

10
src/main/java/hs/fulda/de/ci/exam/project/Admin.java

@ -6,12 +6,18 @@ public class Admin extends Person{
AccountRepository accountRepository; AccountRepository accountRepository;
FlightRepository flightRepository; FlightRepository flightRepository;
AircraftRepository aircraftRepository;
public Admin(String name, Address address, String email, String phone) { public Admin(String name, Address address, String email, String phone) {
super(name, address, email, phone); super(name, address, email, phone);
} }
public void addAircraft(){
public Aircraft addAircraft(String name, String model, int manufacturerYear) throws IOException {
if(name.isBlank()) throw new RuntimeException("Name cannot be null or empty");
if(model.isBlank()) throw new RuntimeException("Model cannot be null or empty");
if(manufacturerYear < 0) throw new RuntimeException("Year cannot be zero");
Aircraft aircraft = new Aircraft(name, model, manufacturerYear);
aircraftRepository.save(aircraft);
return aircraft;
} }
public String searchFlights(String flightNumber){ public String searchFlights(String flightNumber){

5
src/main/java/hs/fulda/de/ci/exam/project/Aircraft.java

@ -33,4 +33,9 @@ public class Aircraft {
public void addFlight(Flight flight) { public void addFlight(Flight flight) {
flights.add(flight); flights.add(flight);
} }
@Override
public String toString() {
return "Aircraft = {" + "name=" + name + '\'' + ", model=" + model + ", manufacturingYear='" + manYear +'}';
}
} }

22
src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java

@ -7,9 +7,7 @@ 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;
@ -26,9 +24,11 @@ public class AdminTest {
Airport airport1_ist; Airport airport1_ist;
Flight flight1; Flight flight1;
Address address1; Address address1;
Aircraft aircraft;
@BeforeEach @BeforeEach
public void setup() { public void setup() {
aircraft = new Aircraft("Boeing", "787", 2003);
address_fr = new Address("Frankfurt str", "Frankfurt", "Hessen", "63023", "Germany"); address_fr = new Address("Frankfurt str", "Frankfurt", "Hessen", "63023", "Germany");
airport_fr = new Airport("Fraport", address_fr, "1234"); airport_fr = new Airport("Fraport", address_fr, "1234");
address1_ist = new Address("Istanbul str", "Istanbul", "Fatih", "9019", "Turkey"); address1_ist = new Address("Istanbul str", "Istanbul", "Fatih", "9019", "Turkey");
@ -39,11 +39,6 @@ public class AdminTest {
@InjectMocks @InjectMocks
Admin admin = new Admin("Max Muster", address1, "example@gmail.com", "012345678" ); Admin admin = new Admin("Max Muster", address1, "example@gmail.com", "012345678" );
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Mock @Mock
private AccountRepository accountRepository; private AccountRepository accountRepository;
@ -118,4 +113,17 @@ public class AdminTest {
}); });
} }
@Mock
private AircraftRepository aircraftRepository;
@Test
public void test_addAircraft_returnsNewAircraft() throws IOException {
try {
when(aircraftRepository.save(any(Aircraft.class))).thenReturn(true);
} catch (IOException e) {
e.printStackTrace();
}
assertNotNull(admin.addAircraft("Boeing", "787", 2003));
}
} }
Loading…
Cancel
Save