Esempio n. 1
0
  public void testGetPhotosViaMockServiceHandlesIOException() throws Exception {

    Photo photo = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo.getId()).andReturn("dummyId1");
    EasyMock.expect(photo.getId()).andReturn("dummyId2");
    PhotosInterface photosInterface =
        (PhotosInterface) EasyMock.createStrictMock(PhotosInterface.class);
    EasyMock.expect(photosInterface.getInfo("31670708", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId1")).andThrow(new IOException());
    EasyMock.expect(photosInterface.getInfo("31671077", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId2")).andThrow(new IOException());
    Flickr flickr = (Flickr) EasyMock.createStrictMock(Flickr.class);
    EasyMock.expect(flickr.getPhotosInterface()).andReturn(photosInterface);

    EasyMock.replay(new Object[] {flickr, photosInterface, photo});

    FlickrFacade flickrFacade = new FlickrFacade(flickr);
    try {
      List photos = flickrFacade.getPhotos(PHOTO_IDS_CSV);
      assertNotNull(photos);
      assertTrue(photos.size() == 0);
    } catch (Exception e) {
      fail("Thrown exception should've been handled by FlickrFacade: " + e);
    }

    EasyMock.verify(new Object[] {flickr, photosInterface, photo});
  }
Esempio n. 2
0
  public void testGetPhotosetsViaMockService() throws Exception {

    Photo photo1 = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo1.getId()).andReturn("dummyId1");
    Photo photo2 = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo2.getId()).andReturn("dummyId2");

    List photosetsPhotos1 = new ArrayList();
    photosetsPhotos1.add(photo1);
    List photosetsPhotos2 = new ArrayList();
    photosetsPhotos2.add(photo2);

    PhotosetsInterface photosetsInterface =
        (PhotosetsInterface) EasyMock.createStrictMock(PhotosetsInterface.class);
    EasyMock.expect(photosetsInterface.getPhotos("711101")).andReturn(photosetsPhotos1);
    EasyMock.expect(photosetsInterface.getPhotos("711155")).andReturn(photosetsPhotos2);

    PhotosInterface photosInterface =
        (PhotosInterface) EasyMock.createStrictMock(PhotosInterface.class);
    EasyMock.expect(photosInterface.getSizes("dummyId1")).andReturn(new ArrayList());
    EasyMock.expect(photosInterface.getSizes("dummyId2")).andReturn(new ArrayList());

    Flickr flickr = (Flickr) EasyMock.createStrictMock(Flickr.class);
    EasyMock.expect(flickr.getPhotosetsInterface()).andReturn(photosetsInterface);
    EasyMock.expect(flickr.getPhotosInterface()).andReturn(photosInterface);

    EasyMock.replay(new Object[] {flickr, photosetsInterface, photosInterface, photo1, photo2});

    FlickrFacade flickrFacade = new FlickrFacade(flickr);
    List photos = flickrFacade.getPhotosFromPhotosets(PHOTOSET_IDS_CSV);
    assertNotNull(photos);
    assertTrue(photos.size() == 2);

    EasyMock.verify(new Object[] {flickr, photosetsInterface, photosInterface, photo1, photo2});
  }
Esempio n. 3
0
  public void testGetPhotosViaMockService() throws Exception {
    Photo photo = (Photo) EasyMock.createStrictMock(Photo.class);
    EasyMock.expect(photo.getId()).andReturn("dummyId1");
    EasyMock.expect(photo.getId()).andReturn("dummyId2");
    PhotosInterface photosInterface =
        (PhotosInterface) EasyMock.createStrictMock(PhotosInterface.class);
    EasyMock.expect(photosInterface.getInfo("31670708", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId1")).andReturn(new ArrayList());
    EasyMock.expect(photosInterface.getInfo("31671077", null)).andReturn(photo);
    EasyMock.expect(photosInterface.getSizes("dummyId2")).andReturn(new ArrayList());
    Flickr flickr = (Flickr) EasyMock.createStrictMock(Flickr.class);
    EasyMock.expect(flickr.getPhotosInterface()).andReturn(photosInterface);

    EasyMock.replay(new Object[] {flickr, photosInterface, photo});

    FlickrFacade flickrFacade = new FlickrFacade(flickr);
    List photos = flickrFacade.getPhotos(PHOTO_IDS_CSV);
    assertNotNull(photos);
    assertTrue(photos.size() == PHOTO_IDS_CSV.split(",").length);

    EasyMock.verify(new Object[] {flickr, photosInterface, photo});
  }