Java – analog type conversion object
•
Java
I have a simple method in the bean to handle cell editing events in the primefaces data table The method is as follows:
public void onCellEdit(CellEditEvent event) { Object oldValue = event.getOldValue(); Object newValue = event.getNewValue(); User user = (User) ((DataTable) event.getComponent()).getRowData(); if (!newValue.equals(oldValue)) user.setUsername(oldValue.toString()); .... }
How can I imitate: user = (user) ((datatable) event getComponent()). getRowData();
Solution
CellEditEvent mockEvent = Mockito.mock(CellEditEvent.class);
CellEditEvent mockEvent = Mockito.mock(CellEditEvent.class); DataTable mockDataTable = Mockito.mock(DataTable.class); Mockito.when(mockEvent.getComponent()).thenReturn(mockDataTable); Mockito.when(mockDataTable.getRowData()).thenReturn(userObj);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码