-1

A fairly straightforward question regarding EasyMock. Read up a bunch of resources but not sure what I am missing:

The following snippet is creating a unit test using Test-ng:

@Test(groups = "unit")
public class SchoolTestEasyMock {

    @Test
    public void test1() {
        School mockSchool = EasyMock.createNiceMock(School.class);
        EasyMock.replay(mockSchool);
        System.out.println(mockSchool.getSchoolNumber());
    }
}

Let's assume the School class has a simple getter 'getSchoolNumber' that returns an Integer.

The snippet above is printing a 'null' to the console. Since I'm creating a 'nice' mock shouldn't the 'getSchoolNumber' return a default value of 0? Am I missing something while creating the nice mock?

juherr
  • 5,640
  • 1
  • 21
  • 63
vksinghh
  • 223
  • 4
  • 16

1 Answers1

3

From the documentation:

If you would like a "nice" Mock Object that by default allows all method calls and returns appropriate empty values (0, null or false), use niceMock() instead.

As Integer is an object, the default value is null. If you change the return type of the method to int, the value will be 0 as expected.

juherr
  • 5,640
  • 1
  • 21
  • 63