### Question:
NcTools { static double getAddOffset(Variable variable) { return getNumericAttributeValue(variable, "add_offset", 0.0); }  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 testGetAddOffset() { final Variable variable = mock(Variable.class); final Attribute attribute = mock(Attribute.class); when(attribute.getNumericValue()).thenReturn(15.812); when(variable.findAttribute("add_offset")).thenReturn(attribute); assertEquals(15.812, NcTools.getAddOffset(variable), 1e-8); verify(variable, times(1)).findAttribute("add_offset"); verifyNoMoreInteractions(variable); }
@Test public void testGetAddOffset_noOffsetAttribute() { final Variable variable = mock(Variable.class); when(variable.findAttribute("add_offset")).thenReturn(null); assertEquals(0.0, NcTools.getAddOffset(variable), 1e-8); verify(variable, times(1)).findAttribute("add_offset"); verifyNoMoreInteractions(variable); }