NTv2GridShiftFactory extends ReferencingFactory implements BufferedFactory { public GridShiftFile createNTv2Grid(URL gridLocation) throws FactoryException { if(gridLocation == null) { throw new FactoryException("The grid location must be not null"); } synchronized (ntv2GridCache) { GridShiftFile grid = ntv2GridCache.get(gridLocation.toExternalForm()); if (grid != null) { return grid; } else { if (gridLocation != null) { grid = loadNTv2Grid(gridLocation); if (grid != null) { ntv2GridCache.put(gridLocation.toExternalForm(), grid); return grid; } } throw new FactoryException("NTv2 Grid " + gridLocation + " could not be created."); } } } NTv2GridShiftFactory();  NTv2GridShiftFactory(final int priority); boolean isNTv2Grid(URL location); GridShiftFile createNTv2Grid(URL gridLocation);  }
@Test public void testCreateNTv2Grid() { boolean factoryExceptionThrown = false; try { factory.createNTv2Grid(null); } catch (FactoryException e) { factoryExceptionThrown = true; } assertTrue(factoryExceptionThrown); factoryExceptionThrown = false; try { factory.createNTv2Grid(INEXISTENT_GRID); } catch (FactoryException e) { factoryExceptionThrown = true; } assertTrue(factoryExceptionThrown); factoryExceptionThrown = false; try { factory.createNTv2Grid(MALFORMED_GRID); } catch (FactoryException e) { factoryExceptionThrown = true; } assertTrue(factoryExceptionThrown); factoryExceptionThrown = false; GridShiftFile grid = null; try { grid = factory.createNTv2Grid(TEST_GRID); } catch (FactoryException e) { factoryExceptionThrown = true; } assertFalse(factoryExceptionThrown); assertNotNull(grid); assertTrue(grid.isLoaded()); }