I am writing J-unit test case for one my method.
A.java
void resetToolbar(final ListSelectionModel lastSelectionModel) {
// attempt to restore the previous page
if (toolbar != null && lastSelectionModel != null) {
gridPanel.setSelectionModel(lastSelectionModel);
}
// Issue occur here..... In PagingToolbar.
toolbar = new PagingToolbar();
}
PagingToolbar.java
class PagingToolbar {
private I18nUtils i18n; //It is a class How should I mock these. i18n
/**
* Creates a new paging toolbar.
*/
public PagingToolbar() {
super();
setDisplayingItemsText(i18n.getText(this, "facebook"));
// here i18n get null and throws null pointer-exception.
}
ATest.java
@Test(groups = { "unit" })
public class ATest {
@Test
public void resetToolbar(){
I18nUtils i18n = createNiceMock(I18nUtils.class);
// Invoke
A tt = new A();
// How to set i18n with reflection in pagingToolbar.
tt.resetToolbar(listselectmodelMock);
}
}
NOTE : In A class in resetToolbar() , I have to invoke pagingToolbar with new keyword.
Aucun commentaire:
Enregistrer un commentaire