### Question:
NcTools { static Number getFillValue(Variable variable) { return getNumericAttributeValue(variable, "_FillValue"); }  static Variable getVariable(NetcdfFile netcdfFile, String variableName); static boolean hasVariable(NetcdfFile netcdfFile, String variableName); static Grid readGrid(NetcdfFile netcdfFile, Variable variable, GridDef expectedGridDef, int z); static Grid readGrid(NetcdfFile netcdfFile, String variableName, GridDef expectedGridDef, int z); static Grid readGrid(NetcdfFile netcdfFile, String variableName, GridDef expectedGridDef);  }### Answer:
@Test public void testGetFillValue() { final Variable variable = mock(Variable.class); final Attribute attribute = mock(Attribute.class); when(attribute.getNumericValue()).thenReturn(16.108); when(variable.findAttribute("_FillValue")).thenReturn(attribute); final Number fillValue = NcTools.getFillValue(variable); assertNotNull(fillValue); assertEquals(16.108, fillValue.doubleValue(), 1e-8); verify(variable, times(1)).findAttribute("_FillValue"); verifyNoMoreInteractions(variable); }
@Test public void testGetFillValue_noFillValuePresent() { final Variable variable = mock(Variable.class); when(variable.findAttribute("_FillValue")).thenReturn(null); final Number fillValue = NcTools.getFillValue(variable); assertNull(fillValue); verify(variable, times(1)).findAttribute("_FillValue"); verifyNoMoreInteractions(variable); }