Advertisement
dzocesrce

[SKIT] Visa Applications

Mar 25th, 2024 (edited)
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.85 KB | None | 0 0
  1. package Lab1;
  2.  
  3. import org.junit.jupiter.api.BeforeEach;
  4. import org.junit.jupiter.api.Test;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import static org.junit.jupiter.api.Assertions.assertEquals;
  10. import static org.junit.jupiter.api.Assertions.assertThrows;
  11.  
  12. public class VisaTest {
  13.  
  14.     private List<String> ukVisaAplications;
  15.     private List<String> usaVisaAplications;
  16.  
  17.     public static List<String> applicationsForUkVisaOnly(List<String> ukVisa, List<String> usaVisa) throws Throwable {
  18.         if(ukVisa==null || usaVisa==null) {
  19.             System.out.println("Actual: NullPointerException");
  20.             throw new NullPointerException();
  21.         }
  22.         int count=0;
  23.         List<String> ukVisaOnly = new ArrayList<String>();
  24.         for(int i=0;i<ukVisa.toArray().length;i++){
  25.             if(!usaVisa.contains(ukVisa.get(i))){
  26.                 ukVisaOnly.add(ukVisa.get(i));
  27.                 count++;
  28.             }
  29.         }
  30.         if(count==0){
  31.             return null;
  32.         }
  33.         else{
  34.             return ukVisaOnly;
  35.         }
  36.     }
  37.     @BeforeEach
  38.     public void init(){
  39.         ukVisaAplications = new ArrayList<String>();
  40.         usaVisaAplications = new ArrayList<String>();
  41. //        System.out.println("NOV TEST");
  42.     }
  43.  
  44.     /*
  45.     Test 1: T T T T C5.2
  46.     Both lists are non-null and non-empty and the return list is also non-empty
  47.      */
  48.  
  49.     @Test
  50.     public void Test1() throws Throwable {
  51.  
  52.         System.out.println("**********");
  53.         System.out.println("TEST 1");
  54.         System.out.println("**********");
  55.  
  56.         ukVisaAplications.add("Dzoce Srce");
  57.         ukVisaAplications.add("Slave Temkov");
  58.         ukVisaAplications.add("Ana Todorovska");
  59.         ukVisaAplications.add("Hristina Mihajloska");
  60.  
  61.         usaVisaAplications.add("Ana Todorovska");
  62.         usaVisaAplications.add("Slave Temkov");
  63.         usaVisaAplications.add("Vlatco Spasev");
  64.         usaVisaAplications.add("Stefan Andonov");
  65.  
  66.     List<String> expectedResult = new ArrayList<>();
  67.     expectedResult.add("Dzoce Srce");
  68.     expectedResult.add("Hristina Mihajloska");
  69.  
  70.     System.out.println("Expected: " + expectedResult.toString());
  71.     System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications).toString());
  72.     assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  73.     }
  74.  
  75.     /*
  76.     Test 2: F T F T C5.2
  77.     First list is null and empty, thus we should be thrown NullPointerException at.
  78.      */
  79.  
  80.     @Test
  81.     public void Test2() throws Throwable {
  82.  
  83.         System.out.println("**********");
  84.         System.out.println("TEST 2");
  85.         System.out.println("**********");
  86.  
  87.         ukVisaAplications = null;
  88.  
  89.         usaVisaAplications.add("Ana Todorovska");
  90.         usaVisaAplications.add("Slave Temkov");
  91.         usaVisaAplications.add("Vlatco Spasev");
  92.         usaVisaAplications.add("Stefan Andonov");
  93.  
  94.         System.out.println("Expected: NullPointerException");
  95.         assertThrows(NullPointerException.class, () -> applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  96.  
  97.     }
  98.  
  99.     /*
  100.     Test 3: T F T F C5.2
  101.     Second list is null and empty, thus we should be thrown NullPointerException at.
  102.      */
  103.  
  104.     @Test
  105.     public void Test3() throws Throwable {
  106.  
  107.         System.out.println("**********");
  108.         System.out.println("TEST 3");
  109.         System.out.println("**********");
  110.  
  111.         usaVisaAplications.add("Ana Todorovska");
  112.         usaVisaAplications.add("Slave Temkov");
  113.         usaVisaAplications.add("Vlatco Spasev");
  114.         usaVisaAplications.add("Stefan Andonov");
  115.  
  116.         usaVisaAplications = null;
  117.  
  118.         System.out.println("Expected: NullPointerException");
  119.         assertThrows(NullPointerException.class, () -> applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  120.  
  121.     }
  122.  
  123.     /*
  124.     Test 4: T T F T C5.1
  125.     First list is empty and as a result we are expecting null.
  126.      */
  127.  
  128.     @Test
  129.     public void Test4() throws Throwable {
  130.  
  131.         System.out.println("**********");
  132.         System.out.println("TEST 4");
  133.         System.out.println("**********");
  134.  
  135.         usaVisaAplications.add("Ana Todorovska");
  136.         usaVisaAplications.add("Slave Temkov");
  137.         usaVisaAplications.add("Vlatco Spasev");
  138.         usaVisaAplications.add("Stefan Andonov");
  139.  
  140.         List<String> expectedResult = new ArrayList<>();
  141.         expectedResult = null;
  142.  
  143.         System.out.println("Expected: " + expectedResult);
  144.         System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  145.         assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  146. //        assertNull(applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  147.     }
  148.  
  149.  
  150.     /*
  151.     Test 5: T T T F C5.2
  152.     Second list is empty, thus we except every element of first list to be returned.
  153.      */
  154.  
  155.     @Test
  156.     public void Test5() throws Throwable {
  157.  
  158.         System.out.println("**********");
  159.         System.out.println("TEST 5");
  160.         System.out.println("**********");
  161.  
  162.         ukVisaAplications.add("Dzoce Srce");
  163.         ukVisaAplications.add("Martin List");
  164.         ukVisaAplications.add("Naum Balkava");
  165.         ukVisaAplications.add("Ace Detelina");
  166.  
  167.         List<String> expectedResult = new ArrayList<>();
  168.         expectedResult.add("Dzoce Srce");
  169.         expectedResult.add("Martin List");
  170.         expectedResult.add("Naum Balkava");
  171.         expectedResult.add("Ace Detelina");
  172.  
  173.         System.out.println("Expected: " + expectedResult.toString());
  174.         System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications).toString());
  175.         assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  176.     }
  177.  
  178.     /*
  179.     Test 6: T T T T C5.1
  180.     Both lists are non-empty, but there all the elements from the first list
  181.     are present in the second list as well, thus it returs null
  182.      */
  183.  
  184.     @Test
  185.     public void Test6() throws Throwable {
  186.  
  187.         System.out.println("**********");
  188.         System.out.println("TEST 6");
  189.         System.out.println("**********");
  190.  
  191.         ukVisaAplications.add("Dzoce Srce");
  192.         ukVisaAplications.add("Ev Genija");
  193.  
  194.         usaVisaAplications.add("Dir Lada");
  195.         usaVisaAplications.add("Ev Genija");
  196.         usaVisaAplications.add("Dzoce Srce");
  197.  
  198.         List<String> expectedResult = new ArrayList<>();
  199.         expectedResult = null;
  200.  
  201.         System.out.println("Expected: " + expectedResult);
  202.         System.out.println("Actual: " + applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  203.         assertEquals(expectedResult,applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  204. //        assertNull(applicationsForUkVisaOnly(ukVisaAplications,usaVisaAplications));
  205.     }
  206.  
  207.  
  208. }
  209.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement