package candystore.datainjection;

import static org.fest.assertions.api.Assertions.assertThat;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import atf.toolbox.data.ScenarioData;
import atf.toolbox.data.TestDataProvider;
import atf.toolbox.data.XMLDataDriver;

/**
 * CalculatorTest
 * 1. Use the ATF Toolbox DataProvider
 * 2. Use the ATF Toolbox XMLDataDriver to drive data from xml into the tests
 */
public class CalculatorTest {

	private static TestDataProvider atfTestDataProvider;
	private static String testDataFilename = "datainjection-calculator-test-data.xml";

	@BeforeClass(alwaysRun=true)
	public static void BeforeClassSetup() {
		atfTestDataProvider = new TestDataProvider();
	}
	
	@DataProvider(name = "AddTwoNumbers")
	   public static Object[][] AdditionData() {
		   String testCaseName = "Test Case: Add 2 Numbers";
	       return atfTestDataProvider.Initialize(new XMLDataDriver(testDataFilename, testCaseName));
	   }
	@DataProvider(name = "MultipleTwoNumbers")
	   public static Object[][] MultiplicationData() {
		   String testCaseName = "Test Case: Multiply 2 Numbers";
	       return atfTestDataProvider.Initialize(new XMLDataDriver(testDataFilename, testCaseName));
	   }
	
	@Test(dataProvider = "AddTwoNumbers", groups = { "datainjection" })
	public void AddTwoNumbers(ScenarioData scenario) {
		int num1 = scenario.getIntParameterData("firstNumber");
		int num2 = scenario.getIntParameterData("secondNumber");
		int expectedResult = scenario.getIntParameterData("expectedSum");
		
		assertThat((num1+num2)).isEqualTo(expectedResult);
	}
	
	@Test(dataProvider = "MultipleTwoNumbers", groups = { "datainjection" })
	public void MultiplyTwoNumbers(ScenarioData scenario) {
		int num1 = scenario.getIntParameterData("firstNumber");
		int num2 = scenario.getIntParameterData("secondNumber");
		int expectedResult = scenario.getIntParameterData("expectedProduct");
		
		assertThat((num1*num2)).isEqualTo(expectedResult);
	}
}

@@ -355,19 +355,16 @@
 atorTest
-%0A *
  1. Use 
@@ -391,19 +391,16 @@
 Provider
-%0A *
  2. Use 
@@ -414,16 +414,19 @@
  Toolbox
+%0A *
  XMLData
@@ -501,17 +501,17 @@
 atorTest
- 
+%0A
 %7B%0A%0A%09priv
@@ -667,17 +667,19 @@
 lwaysRun
-=
+ = 
 true)%0A%09p
@@ -696,17 +696,17 @@
 ic void 
-B
+b
 eforeCla
@@ -714,17 +714,18 @@
 sSetup()
- 
+%0A%09
 %7B%0A%09%09atfT
@@ -769,17 +769,16 @@
 r();%0A%09%7D%0A
-%09
 %0A%09@DataP
@@ -802,35 +802,32 @@
 ddTwoNumbers%22)%0A%09
-   
 public static Ob
@@ -835,17 +835,17 @@
 ect%5B%5D%5B%5D 
-A
+a
 dditionD
@@ -845,32 +845,30 @@
 ditionData()
- 
+%0A%09
 %7B%0A%09%09
-   
 String testC
@@ -898,39 +898,33 @@
 dd 2 Numbers%22;%0A%09
-       
+%09
 return atfTestDa
@@ -998,20 +998,18 @@
 ame));%0A%09
-   
 %7D
+%0A
 %0A%09@DataP
@@ -1046,19 +1046,16 @@
 bers%22)%0A%09
-   
 public s
@@ -1071,17 +1071,17 @@
 ect%5B%5D%5B%5D 
-M
+m
 ultiplic
@@ -1095,16 +1095,14 @@
 ta()
- 
+%0A%09
 %7B%0A%09%09
-   
 Stri
@@ -1157,15 +1157,9 @@
 %22;%0A%09
-       
+%09
 retu
@@ -1249,14 +1249,10 @@
 );%0A%09
-   
 %7D%0A
-%09
 %0A%09@T
@@ -1330,17 +1330,17 @@
 ic void 
-A
+a
 ddTwoNum
@@ -1358,33 +1358,34 @@
 ioData scenario)
- 
+%0A%09
 %7B%0A%09%09int num1 = s
@@ -1551,26 +1551,24 @@
 ectedSum%22);%0A
-%09%09
 %0A%09%09assertTha
@@ -1578,9 +1578,11 @@
 num1
-+
+ + 
 num2
@@ -1614,17 +1614,16 @@
 lt);%0A%09%7D%0A
-%09
 %0A%09@Test(
@@ -1702,17 +1702,17 @@
 ic void 
-M
+m
 ultiplyT
@@ -1743,17 +1743,18 @@
 cenario)
- 
+%0A%09
 %7B%0A%09%09int 
@@ -1936,18 +1936,16 @@
 duct%22);%0A
-%09%09
 %0A%09%09asser
@@ -1955,17 +1955,19 @@
 at((num1
-*
+ * 
 num2)).i

Add comments and clean code