import java.io.FileOutputStream; import java.io.IOException; import java.util.Collection; import formula1.Campionato; import formula1.Pilota; import junit.framework.TestCase; /* * Created on 2-feb-2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author Marco Torchiano * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class TestR5_LetturaFile extends TestCase { private static void writeFile(String fileName,String content) { try{ FileOutputStream fos = new FileOutputStream(fileName); fos.write(content.getBytes()); fos.close(); }catch(IOException ioe){ throw new RuntimeException(ioe.getMessage()); } } public void testLeggiPilota() throws Exception { Campionato c = new Campionato(); String contents= "P:Barrichello\n"+ "P:M.Schumacher\n"+ "P:R.Schumacher\n"; writeFile("info.txt",contents); c.leggiInfo("info.txt"); assertTrue(c.getPilota("Barrichello")!=null); assertTrue(c.getPilota("M.Schumacher")!=null); } public void testLeggiGP() throws Exception { Campionato c = new Campionato(); String contents= "P:Barrichello\n"+ "P:M.Schumacher\n"+ "P:R.Schumacher\n"+ "G:Imola\n" + "G:Monza\n" ; writeFile("info.txt",contents); c.leggiInfo("info.txt"); assertTrue(c.getGranPremio("Imola")!=null); assertTrue(c.getGranPremio("Monza")!=null); } public void testLeggiConSpazi() throws Exception { Campionato c = new Campionato(); String contents= "P:Barrichello\n"+ "P:M.Schumacher\n"+ "P:R.Schumacher\n"+ "G:Imola - San Marino\n" + "G:Monza\n" ; writeFile("info.txt",contents); c.leggiInfo("info.txt"); assertTrue(c.getGranPremio("Imola - San Marino")!=null); } }