❗ All Code will be changed
- Type inferenz
- available since JAVA 7
Map<String, Object> notSoCoolMap = new HashMap<String, Object>();
// will become
Map<String, Object> coolMap = new HashMap<>();
indirect access to static members
// instead of
org.mockito.Mockito.any();
//better do
org.mockito.Matchers.any();
// because this method is declared in Matchers
try-with-resource
@Test
public void traditional() throws Exception {
DataSource dataSource = mock(DataSource.class);
Connection connection = null;
try {
connection = dataSource.getConnection();
} finally {
if (connection != null) {
connection.close();
}
}
}
@Test
public void tryWithResource() throws Exception {
DataSource dataSource = mock(DataSource.class);
try (Connection connection = dataSource.getConnection()) {
// do something
}
}