コード例 #1
0
  /** Test of getWebResource method, of class FileContentLoaderImpl. */
  public void testGetSetWebResource() {
    System.out.println("getWebResource");

    WebResource mockWebResource = EasyMock.createMock(WebResource.class);

    FileContentLoaderImpl instance = new FileContentLoaderImpl(null, null, null);
    instance.setWebResource(mockWebResource);

    assertEquals(mockWebResource, instance.getWebResource());
  }
コード例 #2
0
  /** Test of run method, of class FileContentLoaderImpl. */
  public void testRun1() {
    System.out.println("run");

    Site mockSite = new SiteImpl();
    Page mockPage1 = new PageImpl();
    mockPage1.setURL("http://my.testUrl1.org");
    Page mockPage2 = new PageImpl();
    mockPage2.setURL("http://my.testUrl2.org");

    mockSite.addChild(mockPage1);
    mockSite.addChild(mockPage2);

    ContentFactory mockContentFactory = EasyMock.createMock(ContentFactory.class);
    SSP mockSSP = EasyMock.createMock(SSP.class);

    Date date = new Date();
    DateFactory mockDateFactory = EasyMock.createMock(DateFactory.class);
    EasyMock.expect(mockDateFactory.createDate()).andReturn(date).times(2);

    EasyMock.expect(
            mockContentFactory.createSSP(
                date, "http://my.testUrl1.org", "My Page Content 1", mockPage1, HttpStatus.SC_OK))
        .andReturn(mockSSP)
        .once();

    EasyMock.expect(
            mockContentFactory.createSSP(
                date, "http://my.testUrl2.org", "My Page Content 2", mockPage2, HttpStatus.SC_OK))
        .andReturn(mockSSP)
        .once();

    Map<String, String> fileMap = new HashMap<String, String>();
    fileMap.put("http://my.testUrl1.org", "My Page Content 1");
    fileMap.put("http://my.testUrl2.org", "My Page Content 2");

    EasyMock.replay(mockSSP);
    EasyMock.replay(mockContentFactory);
    EasyMock.replay(mockDateFactory);

    FileContentLoaderImpl instance =
        new FileContentLoaderImpl(mockContentFactory, fileMap, mockDateFactory);
    instance.setWebResource(mockSite);
    instance.run();

    assertTrue(instance.getResult().contains(mockSSP));

    EasyMock.verify(mockSSP);
    EasyMock.verify(mockContentFactory);
    EasyMock.verify(mockDateFactory);
  }