Tuesday, September 21st, 2010
ApplicationContext context =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
MyService service = (MyService) context.getBean("serviceBeanName");
Tags: java, spring
Posted in Development, quick tips | No Comments »
Thursday, September 2nd, 2010
Background
EasyMock version 2.4 introduced some new functionality – the ability to capture the arguments passed to mock objects. As ever a few lines of code speaks volumes.
Capture Example
Test Class
package foo.bar;
import static org.junit.Assert.assertEquals;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;
public class TestServiceImpl {
private Service service;
private Dao dao;
private IMocksControl controller;
private final String description = "description";
@Before
public void setUp() throws Exception {
controller = EasyMock.createStrictControl();
dao = controller.createMock(Dao.class);
service = new ServiceImpl();
service.setDao(dao);
}
@Test
public void testSave() {
Capture <DomainObject> capturedArgument = new Capture <DomainObject>();
dao.save(EasyMock.and(EasyMock.capture(capturedArgument), EasyMock.isA(DomainObject.class)));
controller.replay();
service.save(description);
controller.verify();
DomainObject record = capturedArgument.getValue();
assertEquals(description, record.getDescription());
assertEquals("getNextId", record.getId());
}
}
Source code for classes under test after the break…….
Read More »
Tags: easymock, java, testing
Posted in Development, Examples | No Comments »
Thursday, August 26th, 2010
I was looking for a way to display the Version on the splash screen of my Android app, more specifically, the “versionName” as defined in the application’s AndroidManifest.xml
After A LOT of looking I discovered PackageInfo, which is a Java API to all of the info held in the manifest.
Armed with this information is was easy to produce the following:
private void displayVersionName() {
String versionName = "";
PackageInfo packageInfo;
try {
packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
versionName = "v " + packageInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
TextView tv = (TextView) findViewById(R.id.versionNameTextView);
tv.setText(versionName);
}
Tags: android, java
Posted in Development, How to's | No Comments »
Saturday, July 31st, 2010
The Problem
The project I’m currently working on uses a lot of selenium tests to verify the behaviour of the web front end and, I must say, I’ve been quite impressed with it.
Yesterday however after updating my local machine with the latest copy of the project from Clearcase I noticed a lot of failing tests; the worrying (interesting?) thing though was that the failures appeared to be “random”. Tests were passing one run and failing the next, with no changes having being made in the source code and no changes in the initial starting conditions. I was starting to pull my hair out. Curiously the tests ran fine on my colleagues’ and the build machine. My workmate had a look (remember the tests ran fine for him) but he too was getting the random failures on my machine – we were both stumped.
Read More »
Tags: java, selenium, testing
Posted in quick tips | No Comments »
Wednesday, July 21st, 2010
1. Open the file in Eclipse that you wish to “Dos2Unix”
2. File -> Convert Line Delimiters To -> Unix
Profit!
Tags: dos2unix, eclipse
Posted in quick tips | No Comments »