/**
* GeoDress - A program for reverse geocoding
* Copyright (C) 2010 Stefan T.
*
* See COPYING for Details.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package geodress.tests;
import geodress.exceptions.NoMetaDataException;
import geodress.model.Picture;
import geodress.model.reader.SanselanReader;
import java.io.File;
import java.util.GregorianCalendar;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* Tests the {@link Picture} class.
*
* @author Stefan T.
*/
public class PictureTest {
/** test picture with EXIF data */
private Picture testPictureWithExifBeach;
/** test picture with EXIF data and image description */
private Picture testPictureWithExifSky;
/** test picture without EXIF data */
private Picture testPictureWithoutExif;
/**
* Initializes the objects.
*
* @throws Exception
* may cause an exception
*/
@Before
public void setUp() throws Exception {
/* latitude: +39.50972222 longitude: +2.74916667 */
testPictureWithExifBeach = new Picture(new File("testfiles"
+ File.separator + "beach.jpg"));
testPictureWithExifBeach.registerMetaDataReader(new SanselanReader());
/* latitude: +39.50976 longitude: +2.74928 */
testPictureWithExifSky = new Picture(new File("testfiles"
+ File.separator + "sky.jpg"));
testPictureWithExifSky.registerMetaDataReader(new SanselanReader());
testPictureWithoutExif = new Picture(new File("testfiles"
+ File.separator + "field.jpg"));
testPictureWithoutExif.registerMetaDataReader(new SanselanReader());
}
/**
* Makes a test with coordinates.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testCoordinates1() throws Exception {
Assert.assertEquals(39.5097, testPictureWithExifBeach.getCoordinates()
.getLatitude(), 0.0001);
Assert.assertEquals(2.7492, testPictureWithExifBeach.getCoordinates()
.getLongitude(), 0.0001);
}
/**
* Makes a test with coordinates.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testCoordinates2() throws Exception {
Assert.assertEquals(39.50976, testPictureWithExifSky.getCoordinates()
.getLatitude(), 0.0001);
Assert.assertEquals(2.74928, testPictureWithExifSky.getCoordinates()
.getLongitude(), 0.0001);
}
/**
* Expects an exception if trying to read coordinates from a picture that
* has no meta data.
*
* @throws Exception
* may cause an exception
*/
@Test(expected = NoMetaDataException.class)
public void testNoCoordinates() throws Exception {
testPictureWithoutExif.getCoordinates().getLatitudeAsString();
}
/**
* Makes a test with date/time.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDate1() throws Exception {
Assert.assertEquals(new GregorianCalendar(2009, 06, 18, 11, 54, 38)
.getTimeInMillis(), testPictureWithExifBeach.getDate()
.getTimeInMillis());
Assert.assertEquals("2009-07-18 11:54:38", testPictureWithExifBeach.getDateAsString());
}
/**
* Makes a test with date/time.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDate2() throws Exception {
Assert.assertEquals(new GregorianCalendar(2009, 06, 18, 11, 20, 51)
.getTimeInMillis(), testPictureWithExifSky.getDate()
.getTimeInMillis());
Assert.assertEquals("2009-07-18 11:20:51", testPictureWithExifSky
.getDateAsString());
}
/**
* Makes a test with date/time.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDate3() throws Exception {
Assert.assertEquals(testPictureWithoutExif.lastModified(),
testPictureWithoutExif.getDate().getTimeInMillis());
}
/**
* Makes a test with description.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDescription1() throws Exception {
Assert.assertEquals("Simply blue sky", testPictureWithExifSky
.getDescription());
}
/**
* Makes a test with description.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDescription2() throws Exception {
Assert.assertEquals(Picture.NO_DATA, testPictureWithExifBeach
.getDescription());
}
}