PropertiesUtil { public void saveLastKey() throws IOException { FileOutputStream fos = null; try { fos = new FileOutputStream(file); properties.store(fos, null); } finally { if (fos != null) { fos.close(); } } } PropertiesUtil(File file); String getProperty(String key); PropertiesUtil setProperty(String key, String value); void saveLastKey(); Properties getProperties(); void setProperties(Properties properties);  }
@Test(groups = { "TestPropertiesUtil" }, dependsOnMethods = { "testsetProperties" }) public void testSaveLastKey() { StringBuffer sb = new StringBuffer(); Reader rd = null; try { propertiesUtil.saveLastKey(); BufferedInputStream bin = new BufferedInputStream(new FileInputStream(file)); rd = new InputStreamReader(bin, "UTF-8"); int c = 0; while ((c = rd.read()) != -1) { sb.append((char) c); } } catch (IOException e) { } finally { try { if (rd != null) { rd.close(); } } catch (IOException e) { } } assertTrue(sb.toString().contains("name=name1")); assertTrue(sb.toString().contains("value=value1")); }