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