cloudsim-plus-master/cloudsim-plus-master/cloudsim-plus/src/test/java/org/cloudbus/cloudsim/resources/HarddriveStorageTest.java
@Test
    public void testReserveSpaceNotReservedFile3() {
        final int fileSize = FILE_SIZE;
        final int halfFileSize = fileSize/2;
        final long capacity = (long)fileSize;
        final long available = (long)halfFileSize;
        final HarddriveStorage instance = createHardDrive(capacity);
        assertEquals(0, instance.getAllocatedResource());

        final File file = createNumberedFile(1, fileSize);
        assertTrue(instance.reserveSpace(halfFileSize));
        try{
            instance.addReservedFile(file);
            fail("The reserved file was added but its space was not totally reserved before.");
        } catch(Exception e){
            /*if the exception was thrown, indicates that the file
            was accordingly not added because not the entire space was previously
            reserved.
            Now, checks the available space to see if remains unchanged.*/
            assertEquals(available, instance.getAvailableResource());
            assertEquals(available,  instance.getAllocatedResource());
        }

        //accordingly, reserves space previously and then adds the reserved file
        assertTrue(instance.reserveSpace(halfFileSize));
        assertTrue(instance.addReservedFile(file) > 0);
        assertEquals(0, instance.getAvailableResource());
        assertEquals(capacity, instance.getAllocatedResource());
    }
/**
     * Try to add a reserved file which the space was not totally reserved
     * before.
     * An exception must be thrown in that case.
     */
Try to add a reserved file which the space was not totally reserved
before.
An exception must be thrown in that case.
Try to add a reserved file which the space was not totally reserved before . An exception must be thrown in that case .
@Test
    public void testReserveSpaceNotReservedFile3() {
        final int fileSize = FILE_SIZE;
        final int halfFileSize = fileSize/2;
        final long capacity = (long)fileSize;
        final long available = (long)halfFileSize;
        final HarddriveStorage instance = createHardDrive(capacity);
        assertEquals(0, instance.getAllocatedResource());
        final File file = createNumberedFile(1, fileSize);
        assertTrue(instance.reserveSpace(halfFileSize));
        try{
            instance.addReservedFile(file);
            fail("The reserved file was added but its space was not totally reserved before.");
        } catch(Exception e){
            /*if the exception was thrown, indicates that the file
            was accordingly not added because not the entire space was previously
            reserved.
            Now, checks the available space to see if remains unchanged.*/
            assertEquals(available, instance.getAvailableResource());
            assertEquals(available,  instance.getAllocatedResource());
        }
        assertTrue(instance.reserveSpace(halfFileSize));
        assertTrue(instance.addReservedFile(file) > 0);
        assertEquals(0, instance.getAvailableResource());
        assertEquals(capacity, instance.getAllocatedResource());
    }
@ Test public void testReserveSpaceNotReservedFile3 ( ) { final int fileSize = FILE_SIZE ; final int halfFileSize = fileSize / 2 ; final long capacity = ( long ) fileSize ; final long available = ( long ) halfFileSize ; final HarddriveStorage instance = createHardDrive ( capacity ) ; assertEquals ( 0 , instance . getAllocatedResource ( ) ) ; final File file = createNumberedFile ( 1 , fileSize ) ; assertTrue ( instance . reserveSpace ( halfFileSize ) ) ; try { instance . addReservedFile ( file ) ; fail ( "The reserved file was added but its space was not totally reserved before." ) ; } catch ( Exception e ) { /*if the exception was thrown, indicates that the file
            was accordingly not added because not the entire space was previously
            reserved.
            Now, checks the available space to see if remains unchanged.*/ assertEquals ( available , instance . getAvailableResource ( ) ) ; assertEquals ( available , instance . getAllocatedResource ( ) ) ; } assertTrue ( instance . reserveSpace ( halfFileSize ) ) ; assertTrue ( instance . addReservedFile ( file ) > 0 ) ; assertEquals ( 0 , instance . getAvailableResource ( ) ) ; assertEquals ( capacity , instance . getAllocatedResource ( ) ) ; }
Try to add a reserved file which the space was not totally reserved
 before.
Try to add a reserved file which the space was not totally reserved before .
//accordingly, reserves space previously and then adds the reserved file