Download validations using hamcrest

Download validations using hamcrest

For download validations we need hamcrest dependency in our project

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-all</artifactId>
    <version>1.3</version>
  </dependency>

Then we go to the below address and download the zip file named DisableMonitor and save it in our project.

https://github.com/Eun/DisableMonitor

We also right click on the file to be downloaded in the browser and get its link by copying link address

"https://github.com/Eun/DisableMonitor/releases/download/G1.92/DisableMonitor-G1.92.zip"

Then we use hamcrest library to compare size of both files like this . I.e compare size of file we downloaded and saved in our project and the one that is lying on the server on the above address.

@Test
public void verifyDownloadTest(){
        
File inputFile = new File(System.getProperty("user.dir")+File.separator+("DisableMonitor-G1.92.zip"));
int expectedValue = (int)inputFile.length();
        
System.out.println("The downloaded input file is "+inputFile);
System.out.println("The size of downloaded input file is "+inputFile.length());
        
byte[] actualValue = given().get("https://github.com/Eun/DisableMonitor/releases/download/G1.92/DisableMonitor-G1.92.zip").then().extract().asByteArray();
         
System.out.println("The expected file is "+ actualValue);

System.out.println("The expected size of file is "+ actualValue.length());

            
assertThat(expectedValue,equalTo(actualValue.length));
}