Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab1;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import java.util.ArrayList;
- import java.util.List;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertThrows;
- public class VisaTest {
- private List<String> ukVisaAplications;
- private List<String> usaVisaAplications;
- public static List<String> applicationsForUkVisaOnly(List<String> ukVisa, List<String> usaVisa) throws Throwable {
- if(ukVisa==null || usaVisa==null) {
- System.out.println("Actual: NullPointerException");
- throw new NullPointerException();
- }
- int count=0;
- List<String> ukVisaOnly = new ArrayList<String>();
- for(int i=0;i<ukVisa.toArray().length;i++){
- if(!usaVisa.contains(ukVisa.get(i))){
- ukVisaOnly.add(ukVisa.get(i));
- count++;
- }
- }
- if(count==0){
- return null;
- }
- else{
- return ukVisaOnly;
- }
- }
- @BeforeEach
- public void init(){
- ukVisaAplications = new ArrayList<String>();
- usaVisaAplications = new ArrayList<String>();
- // System.out.println("NOV TEST");
- }
- /*
- Test 1: T T T T C5.2
- Both lists are non-null and non-empty and the return list is also non-empty
- */
- @Test
- public void Test1() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 1");
- System.out.println("**********");
- ukVisaAplications.add("Dzoce Srce");
- ukVisaAplications.add("Slave Temkov");
- ukVisaAplications.add("Ana Todorovska");
- ukVisaAplications.add("Hristina Mihajloska");
- usaVisaAplications.add("Ana Todorovska");
- usaVisaAplications.add("Slave Temkov");
- usaVisaAplications.add("Vlatco Spasev");
- usaVisaAplications.add("Stefan Andonov");
- List<String> expectedResult = new ArrayList<>();
- expectedResult.add("Dzoce Srce");
- expectedResult.add("Hristina Mihajloska");
- System.out.println("Expected: " + expectedResult.toString());
- System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications).toString());
- assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- }
- /*
- Test 2: F T F T C5.2
- First list is null and empty, thus we should be thrown NullPointerException at.
- */
- @Test
- public void Test2() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 2");
- System.out.println("**********");
- ukVisaAplications = null;
- usaVisaAplications.add("Ana Todorovska");
- usaVisaAplications.add("Slave Temkov");
- usaVisaAplications.add("Vlatco Spasev");
- usaVisaAplications.add("Stefan Andonov");
- System.out.println("Expected: NullPointerException");
- assertThrows(NullPointerException.class, () -> applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- }
- /*
- Test 3: T F T F C5.2
- Second list is null and empty, thus we should be thrown NullPointerException at.
- */
- @Test
- public void Test3() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 3");
- System.out.println("**********");
- usaVisaAplications.add("Ana Todorovska");
- usaVisaAplications.add("Slave Temkov");
- usaVisaAplications.add("Vlatco Spasev");
- usaVisaAplications.add("Stefan Andonov");
- usaVisaAplications = null;
- System.out.println("Expected: NullPointerException");
- assertThrows(NullPointerException.class, () -> applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- }
- /*
- Test 4: T T F T C5.1
- First list is empty and as a result we are expecting null.
- */
- @Test
- public void Test4() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 4");
- System.out.println("**********");
- usaVisaAplications.add("Ana Todorovska");
- usaVisaAplications.add("Slave Temkov");
- usaVisaAplications.add("Vlatco Spasev");
- usaVisaAplications.add("Stefan Andonov");
- List<String> expectedResult = new ArrayList<>();
- expectedResult = null;
- System.out.println("Expected: " + expectedResult);
- System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- // assertNull(applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- }
- /*
- Test 5: T T T F C5.2
- Second list is empty, thus we except every element of first list to be returned.
- */
- @Test
- public void Test5() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 5");
- System.out.println("**********");
- ukVisaAplications.add("Dzoce Srce");
- ukVisaAplications.add("Martin List");
- ukVisaAplications.add("Naum Balkava");
- ukVisaAplications.add("Ace Detelina");
- List<String> expectedResult = new ArrayList<>();
- expectedResult.add("Dzoce Srce");
- expectedResult.add("Martin List");
- expectedResult.add("Naum Balkava");
- expectedResult.add("Ace Detelina");
- System.out.println("Expected: " + expectedResult.toString());
- System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications).toString());
- assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- }
- /*
- Test 6: T T T T C5.1
- Both lists are non-empty, but there all the elements from the first list
- are present in the second list as well, thus it returs null
- */
- @Test
- public void Test6() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 6");
- System.out.println("**********");
- ukVisaAplications.add("Dzoce Srce");
- ukVisaAplications.add("Ev Genija");
- usaVisaAplications.add("Dir Lada");
- usaVisaAplications.add("Ev Genija");
- usaVisaAplications.add("Dzoce Srce");
- List<String> expectedResult = new ArrayList<>();
- expectedResult = null;
- System.out.println("Expected: " + expectedResult);
- System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- // assertNull(applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement