@Test public void testBeanHashCode() { TestBean aBean = new TestBean("John", "Doe", "blue"); TestBean thatBean = new TestBean("John", "Doe", "blue"); assertEquals(thatBean, aBean); assertEquals(thatBean.hashCode(), aBean.hashCode()); }
private File createDelimitedFile(Set<TestBean> theBeans) { File aDelimitedFile = null; try { // Create a temporary file ... aDelimitedFile = createTempFile(this.getClass().getName(), ".csv"); aDelimitedFile.deleteOnExit(); // Write the set of beans out to the file ... BufferedWriter aWriter = new BufferedWriter(new FileWriter(aDelimitedFile)); for (TestBean aBean : theBeans) { StringBuilder aStringBuilder = new StringBuilder(); aStringBuilder.append(aBean.getFirstName()); aStringBuilder.append(DEFAULT_DELIMITER); aStringBuilder.append(aBean.getLastName()); aStringBuilder.append(DEFAULT_DELIMITER); aStringBuilder.append(aBean.getFavoriteColor()); aWriter.append(aStringBuilder); aWriter.newLine(); } // File all buffers and close up shop ... aWriter.flush(); aWriter.close(); } catch (IOException e) { fail("Failed to create test delimited file.", e); } return aDelimitedFile; }