001 package org.hackystat.sensor.xmldata.option; 002 003 import java.io.File; 004 import java.util.ArrayList; 005 import java.util.List; 006 007 import org.hackystat.sensor.xmldata.XmlDataController; 008 import org.junit.Assert; 009 import org.junit.Test; 010 011 /** 012 * Tests if the arglist option operates as intended. 013 * @author aito 014 * 015 */ 016 public class TestArgListOption { 017 /** 018 * Tests if isValid returns the correct value depending on the specified 019 * parameters. 020 */ 021 @Test 022 public void testIsValid() { 023 XmlDataController controller = new XmlDataController(); 024 // Tests a valid argList parameter count, but invalid file. 025 List<String> parameters = new ArrayList<String>(); 026 String testPackage = "src/org/hackystat/sensor/xmldata/testdataset/"; 027 File testArgList = new File(System.getProperty("user.dir"), testPackage + "testArgList.txt"); 028 //parameters.add(new File("") + testPackage + "testArgList.txt"); 029 parameters.add(testArgList.toString()); 030 Option option = OptionFactory.getInstance(controller, ArgListOption.OPTION_NAME, 031 parameters); 032 Assert.assertTrue("ArgList accept only 1 argument.", option.isValid()); 033 option.process(); 034 035 // Tests passing invalid amount of parameters. 036 parameters = new ArrayList<String>(); 037 option = new ArgListOption(controller, parameters); 038 Assert.assertFalse("ArgList accept only 1 argument.", option.isValid()); 039 040 // Tests passing an invalid file. 041 parameters = new ArrayList<String>(); 042 parameters.add("Foo.xml"); 043 option = new ArgListOption(controller, parameters); 044 Assert.assertFalse("An invalid file should invalid this option.", option.isValid()); 045 } 046 }