import java.util.Collection; import java.util.Iterator; import junit.framework.TestCase; import files.*; public class TestR1_HardDisk extends TestCase { public TestR1_HardDisk(String arg0) { super(arg0); } public void testCreazione() { Computer pc = new Computer(); HardDisk hd1 = new HardDisk(10 * HardDisk.GB); HardDisk hd2 = new HardDisk(20 * HardDisk.GB); pc.add(hd1); pc.add(hd2); // in ordine di lettera Collection dischi = pc.elencoDischi(); assertEquals(2, dischi.size()); Iterator it = dischi.iterator(); HardDisk hdPrimo = (HardDisk) it.next(); HardDisk hdSecondo = (HardDisk) it.next(); assertSame(hd1, hdPrimo); assertSame(hd2, hdSecondo); } public void testDatiHD() { Computer pc = new Computer(); HardDisk hd1 = new HardDisk(10 * HardDisk.GB); HardDisk hd2 = new HardDisk(20 * HardDisk.GB); pc.add(hd1); pc.add(hd2); // in ordine di lettera Collection dischi = pc.elencoDischi(); assertEquals(2, dischi.size()); Iterator it = dischi.iterator(); HardDisk hd = (HardDisk) it.next(); assertEquals('C', hd.getId()); assertEquals(10 * HardDisk.GB, hd.getSize()); assertEquals(10 * HardDisk.GB, hd.getAvailable()); // capacità massima e capacità residua sono uguali // dato che all'inizio l'HD è vuoto hd = (HardDisk) it.next(); assertEquals('D', hd2.getId()); assertEquals(20 * HardDisk.GB, hd2.getSize()); } public void testGetDisk() { Computer pc = new Computer(); HardDisk hd1 = new HardDisk(10 * HardDisk.GB); pc.add(hd1); // E' possibile accedere ai dischi in maniera diretta HardDisk hdc = pc.getDisk('C'); assertSame(hd1, hdc); } public void testGetWNoDisk() { Computer pc = new Computer(); HardDisk hdc = pc.getDisk('C'); assertSame(null, hdc); } public void testElencoDischiNoDisk() { Computer pc = new Computer(); Collection dischi = pc.elencoDischi(); assertEquals(0, dischi.size()); } }