Skip to content

Instantly share code, notes, and snippets.

@jieniu
Created January 12, 2019 04:01
Show Gist options
  • Save jieniu/1136aacd63035876da8fc7aaf9d2afba to your computer and use it in GitHub Desktop.
Save jieniu/1136aacd63035876da8fc7aaf9d2afba to your computer and use it in GitHub Desktop.
inject mock object when ut
@RunWith(PowerMockRunner.class)
@PrepareForTest({DatasetInfoDao.class, DatasetResource.class})
public class DatasetResourceTest {
@Test
public void testIsDumpTimingValidTrue() throws Exception {
DatasetInfoDao dao = PowerMockito.mock(DatasetInfoDao.class);
PowerMockito.when(dao, "getCreatetimeByGroupIdAndDocName", Mockito.any(String.class), Mockito.any(String.class)).thenReturn(null);
DatasetResource resource = PowerMockito.spy(new DatasetResource());
MemberModifier.field(DatasetResource.class, "datasetInfoDao").set(resource, dao);
boolean ret = resource.dumpTimingValidation("1001", "tablename");
Assert.assertTrue(ret==true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment