How to use UtilTest class of org.easymock.tests package

Best Easymock code snippet using org.easymock.tests.UtilTest

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1// Copyright 2010 Google Inc. All Rights Reserved.
2
3package com.google.appinventor.blockseditor.jsonp;
4
5import com.google.appinventor.common.testutils.TestUtils;
6
7import junit.framework.TestCase;
8
9import org.easymock.EasyMock;
10
11import java.io.File;
12import java.io.FileInputStream;
13import java.io.FileNotFoundException;
14import java.io.IOException;
15import java.io.InputStream;
16import java.net.URLConnection;
17import java.util.Map;
18
19
20/**
21 * Unit tests for {@link Util}.
22 *
23 * @author sharon@google.com (Sharon Perl)
24 */
25public class UtilTest extends TestCase {
26
27  private URLConnection mockConn = EasyMock.createMock(URLConnection.class);
28  private static final String TESTING_SOURCE_PATH = TestUtils.APP_INVENTOR_ROOT_DIR +
29      "/blockseditor/tests/com/google/appinventor/blockseditor/jsonp/testing_source_files/";
30
31
32  public void testDownloadZipFile() throws FileNotFoundException, IOException {
33    File zipFile = new File(TESTING_SOURCE_PATH + "zipfile.zip");
34    InputStream zipInput = new FileInputStream(zipFile);
35    assertNotNull(zipInput);
36    
37    EasyMock.expect(mockConn.getInputStream()).andReturn(zipInput);
38    EasyMock.replay(mockConn);
39    
40    Map<String,String> zipFiles = Util.downloadZipFile(mockConn);
41    // check that we got back the files we expect
42    assertTrue(zipFiles.containsKey("assets/cat.wav"));
43    assertTrue(zipFiles.containsKey("assets/kitty.jpg"));
44    assertEquals(2, zipFiles.size());
45    // check that we were able to give the unzipped files their proper names
46    assertTrue(zipFiles.get("assets/cat.wav").contains("assets/cat.wav"));
47    assertTrue(zipFiles.get("assets/kitty.jpg").contains("assets/kitty.jpg"));
48    // check that we extracted the file contents that we expect
49    assertTrue(filesEqual(TESTING_SOURCE_PATH + "assets/cat.wav", zipFiles.get("assets/cat.wav")));
50    assertTrue(filesEqual(TESTING_SOURCE_PATH + "assets/kitty.jpg", 
51        zipFiles.get("assets/kitty.jpg")));
52    EasyMock.verify(mockConn);
53  }
54  
55  private String basename(String path) {
56    return path.substring(path.lastIndexOf('/') + 1);
57  }
58  
59  private boolean filesEqual(String filePath1, String filePath2) throws IOException {
60    File file1 = new File(filePath1);
61    File file2 = new File(filePath2);
62    InputStream inp1 = new FileInputStream(file1);
63    InputStream inp2 = new FileInputStream(file2);
64    int b1;
65    int b2;
66    while ((b1 = inp1.read()) == (b2 = inp2.read()) && b1 != -1);
67    if (b1 != -1 || b2 != -1) {
68      return false;
69    }
70    return true;
71  }
72}
73
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on UtilTest

    No relevant questions found for this class 😞

Most used methods in UtilTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)