HmsUpgradeUtil { public static UpgradeStatus loadUpgradeStatus( final String fileNameAbsPath ) { if ( StringUtils.isBlank( fileNameAbsPath ) ) { return null; } File upgradeStatusFile = new File( fileNameAbsPath ); if ( upgradeStatusFile.exists() && upgradeStatusFile.isFile() ) { return HmsUpgradeUtil.loadUpgradeStatus( new File( fileNameAbsPath ) ); } else { logger.error( "Either '{}' does not exist or is not a file.", fileNameAbsPath ); return null; } } private  HmsUpgradeUtil(); static boolean saveUpgradeStatus( final String fileNameAbsPath, final UpgradeStatus upgradeStatus ); static boolean saveUpgradeStatus( final File upgradeStatusFile, final UpgradeStatus upgradeStatus ); static UpgradeStatus loadUpgradeStatus( final String fileNameAbsPath ); static UpgradeStatus loadUpgradeStatus( final File upgradeStatusFile );  }
@Test public void testLoadUpgradeStatus() { String upgradeStatusFileName = null; assertNull( HmsUpgradeUtil.loadUpgradeStatus( upgradeStatusFileName ) ); Calendar cal = Calendar.getInstance(); String timeInMillis = Long.toString( cal.getTimeInMillis() ); String id = UUID.randomUUID().toString(); UpgradeStatusCode statusCode = UpgradeStatusCode.HMS_UPGRADE_INITIATED; UpgradeStatus upgradeStatus = new UpgradeStatus(); upgradeStatus.setId( id ); upgradeStatus.setStatusCode( statusCode ); upgradeStatusFileName = upgradeDir + File.separator + timeInMillis + ".json"; assertTrue( HmsUpgradeUtil.saveUpgradeStatus( upgradeStatusFileName, upgradeStatus ) ); File upgradeStatusFile = new File( upgradeStatusFileName ); assertTrue( upgradeStatusFile.exists() && upgradeStatusFile.isFile() ); UpgradeStatus status = HmsUpgradeUtil.loadUpgradeStatus( upgradeStatusFileName ); assertNotNull( status ); assertEquals( status.getId(), upgradeStatus.getId() ); assertEquals( status.getStatusCode(), upgradeStatus.getStatusCode() ); assertTrue( upgradeStatusFile.delete() ); File upgradeDirFile = new File( upgradeDir ); if ( upgradeDirFile.exists() && upgradeDirFile.isDirectory() ) { upgradeDirFile.delete(); } }