Sona Markosyan
3 years ago
6 changed files with 99 additions and 13 deletions
-
4src/main/java/hs/fulda/de/ci/exam/project/Account.java
-
30src/main/java/hs/fulda/de/ci/exam/project/AccountRepository.java
-
27src/main/java/hs/fulda/de/ci/exam/project/Admin.java
-
5src/main/java/hs/fulda/de/ci/exam/project/FlightRepository.java
-
12src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java
-
34src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java
@ -1,9 +1,29 @@ |
|||
package hs.fulda.de.ci.exam.project; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collection; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
public interface AccountRepository { |
|||
ArrayList<Account> findAll(); |
|||
void save(Account account); |
|||
boolean addPersonalDetails(Person person); |
|||
public class AccountRepository { |
|||
Map<String, Account> accountList = new ConcurrentHashMap<String, Account>(); |
|||
Map<Account, Person> personalInfo = new ConcurrentHashMap<>(); |
|||
|
|||
public boolean checkIfAccountAlreadyExist(Account account){ |
|||
if(accountList.containsKey(generateKey(account))){ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
private String generateKey(Account account) { |
|||
return String.format("%s", account.getId()); |
|||
} |
|||
public Collection<Account> findAll() { |
|||
return accountList.values(); |
|||
} |
|||
public void save(Account account){ |
|||
accountList.put(generateKey(account), account); |
|||
} |
|||
public void addPersonalDetails(Person person, String id){ |
|||
personalInfo.put(accountList.get(id), person); |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
package hs.fulda.de.ci.exam.project; |
|||
|
|||
public class Admin extends Person{ |
|||
|
|||
AccountRepository accountRepository; |
|||
FlightRepository flightRepository; |
|||
public Admin(String name, Address address, String email, String phone) { |
|||
super(name, address, email, phone); |
|||
} |
|||
|
|||
public void addAircraft(){ |
|||
|
|||
} |
|||
|
|||
public void addFlight(String flightNumber, Airport departure, Airport arrival, int durationInMinutes ){ |
|||
Flight flight = new Flight(flightNumber, departure, arrival, durationInMinutes ); |
|||
flightRepository.save(flight); |
|||
} |
|||
|
|||
public boolean blockUser(Account user){ |
|||
if(accountRepository.checkIfAccountAlreadyExist(user)){ |
|||
user.setStatus(Account.AccountStatus.BLOCKED); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
package hs.fulda.de.ci.exam.project; |
|||
|
|||
public interface FlightRepository { |
|||
void save(Flight flight); |
|||
} |
@ -0,0 +1,34 @@ |
|||
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 org.mockito.junit.jupiter.MockitoExtension; |
|||
import java.util.ArrayList; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
import static org.mockito.Mockito.when; |
|||
|
|||
@ExtendWith(MockitoExtension.class) |
|||
public class AdminTest { |
|||
|
|||
final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); |
|||
|
|||
@InjectMocks |
|||
Admin admin = new Admin("Max Muster", address1, "example@gmail.com", "012345678" ); |
|||
|
|||
@Mock |
|||
private AccountRepository accountRepository; |
|||
|
|||
@Test |
|||
public void test_blockUser() { |
|||
ArrayList<Account> users = new ArrayList<>(); |
|||
Account user = new Account("john5", "password", Account.AccountStatus.ACTIVE); |
|||
when(accountRepository.checkIfAccountAlreadyExist(user)).thenReturn(true); |
|||
|
|||
admin.blockUser(user); |
|||
|
|||
assertEquals(Account.AccountStatus.BLOCKED, user.getStatus(), "Status successfully changed"); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue