Consider the following test class:
public class MyTest extends extends EasyMockSupport {
private static TestobjectFactory testobjectFactory = new TestobjectFactory();
private static final Date DATE = testobjectFactory.createDate(2013, 0, 13, 01, 02, 03);
private static final String CSV = "einCsv";
@TestSubject
private ClassToBeTested classUnderTest = new ClassToBeTested();
@Mock
private ClassToBeMocked myMock;
@After
public void tearDown() {
verifyAll();
}
@Test
public void myTest() throws Exception {
replayAll();
String outcome = classUnderTest.someMethod("", DATE);
assertThat(outcome, is(""));
}
@Test
public void anotherTest() throws Exception {
expect(myMock.mockedMethod((String[]) anyObject())).andReturn(testobjectFactory.foo());
replayAll();
String outcome = classUnderTest.someMethod(CSV, DATE);
assertTrue(outcome.contains("abc"));
}
}
Questions:
Why would you define CSV (or DATE) static final? Defining it final I agree as it's constant. But why static?
Which fields are written in uppercase? private static final MY_FIELD; private final MY_FIELD; private static MY_FIELD;
Wouldn't it be better to use a static TestobjectFactory?
Edit:
I already saw that post from the possible duplicate before. But the questions I wrote don't have an answer in there.