/**
* Tests the {@link IdentifiedObjectFinder#find} method.
*/
@Test
public void testFind() throws FactoryException {
final GeographicCRS CRS84 = factory.createGeographicCRS("CRS:84");
final IdentifiedObjectFinder finder = factory.getIdentifiedObjectFinder(CoordinateReferenceSystem.class);
assertTrue("Newly created finder should default to full scan.", finder.isFullScanAllowed());
finder.setFullScanAllowed(false);
assertSame("Should find without the need for scan, since we can use the CRS:84 identifier.",
CRS84, finder.find(CRS84));
finder.setFullScanAllowed(true);
assertSame("Allowing scanning should not make any difference for this CRS84 instance.",
CRS84, finder.find(CRS84));
assertNotSame("Required condition for next test.", CRS84, DefaultGeographicCRS.WGS84);
assertFalse ("Required condition for next test.", CRS84.equals(DefaultGeographicCRS.WGS84));
assertTrue ("Required condition for next test.", CRS.equalsIgnoreMetadata(CRS84, DefaultGeographicCRS.WGS84));
finder.setFullScanAllowed(false);
assertNull("Should not find WGS84 without a full scan, since it doesn't contains the CRS:84 identifier.",
finder.find(DefaultGeographicCRS.WGS84));
finder.setFullScanAllowed(true);
assertSame("A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.",
CRS84, finder.find(DefaultGeographicCRS.WGS84));
finder.setFullScanAllowed(false);
assertNull("The scan result should not be cached.",
finder.find(DefaultGeographicCRS.WGS84));
// --------------------------------------------------
// Same test than above, using a CRS created from WKT
// --------------------------------------------------
String wkt = "GEOGCS[\"WGS 84\",\n" +
" DATUM[\"WGS84\",\n" +
" SPHEROID[\"WGS 84\", 6378137.0, 298.257223563]],\n" +
" PRIMEM[\"Greenwich\", 0.0],\n" +
" UNIT[\"degree\", 0.017453292519943295]]";
CoordinateReferenceSystem search = CRS.parseWKT(wkt);
assertFalse("Required condition for next test.", CRS84.equals(search));
assertTrue ("Required condition for next test.", CRS.equalsIgnoreMetadata(CRS84, search));
finder.setFullScanAllowed(false);
assertNull("Should not find WGS84 without a full scan, since it doesn't contains the CRS:84 identifier.",
finder.find(search));