Home | History | Annotate | Download | only in testng387
      1 package test.testng387;
      2 
      3 import java.util.ArrayList;
      4 import java.util.Arrays;
      5 import java.util.Iterator;
      6 import java.util.List;
      7 
      8 import org.testng.annotations.DataProvider;
      9 import org.testng.annotations.Test;
     10 
     11 /**
     12  * test for http://jira.opensymphony.com/browse/TESTNG-387
     13  * The invocation-numbers logic in failed.xml is wrong for dataprovider and parallel=true
     14  *
     15  * The test will throw exception when numbers are prime, so getFailedInvocationNumbers() should be a list of prime numbers.
     16  *
     17  * @author freynaud
     18  */
     19 public class FailedDPTest {
     20 	static final List<Integer> primes = Arrays.asList(2, 3, 5, 7);
     21 
     22 	/**
     23 	 * DP generating all number from 0 to 9.
     24 	 * */
     25 	@DataProvider(name = "DP", parallel = true)
     26 	public Iterator<Integer[]> getData() {
     27 		List<Integer[]> list = new ArrayList<>();
     28 		for (int i = 0; i < 10; i++) {
     29 			list.add(new Integer[] { i });
     30 		}
     31 		return list.iterator();
     32 	}
     33 
     34 	/**
     35 	 * Throws an exception for a prime number.
     36 	 * @throws Exception
     37 	 */
     38 	@Test(dataProvider = "DP", groups = { "DPTest" })
     39 	public void isNotPrime(Integer i) throws Exception {
     40 		if (primes.contains(i)){
     41 			throw new Exception(i+" is prime");
     42 		}
     43 	}
     44 
     45 }
     46