To test method1
you just need to test it like any other method. The Object under test in this case the Singleton class should not be mocked.
Create a test object i.e. your class under test (testee) usually in a setup method then:
@Test
public void testMethod1() {
int testValue = 1;
int expectedResult = 2;
assertThat(testee.method1(testValue), equalTo(expectedResult));
}
In the example above I would use parametrized testing with something like JUnitParams to test boundaries for example, Integer MAX_VALUE etc.
@Test
@Parameters(method = "method1Params")
public void testMethod1(int testValue, int expectedResult) {
assertThat(testee.method1(testValue), equalTo(expectedResult));
}
@Ignore
private final Object[] method1Params() {
return new Object[] {
new Object { 1, 2 },
new Object { -2, -1 }
};
}
Mocking is mainly used when you want to test the SUT, in this case the Singleton in isolation from other components (collaborators) to ensure it behaves correctly. In this case it is not necessary.
When you could use a mock
public int method1(DependedOnComponent doc) {
int a = 1;
int ret = doc.method2(a);
return ret;
}
then
@Test
public void testMethod1() {
DependedOnComponent mockDOC = mock(DependedOnComponent.class);
// When method2() is called you control the value returned
when(mockDOC.method2(1)).thenReturn(2);
assertThat(testee.method1(mockDOC), equalTo(2));
}