Skip to content

Commit

Permalink
Refs #10376 Update ReflMainViewPresenter unit test
Browse files Browse the repository at this point in the history
* Add expectations for setTableList
* Remove unnecessary check points. setTableList was being called many
  times after a checkpoint (which had cleared expectations), causing
  many uninteresting calls to setTableList to issue warnings.
  • Loading branch information
Harry Jeffery committed Oct 20, 2014
1 parent 14c455e commit acc0692
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
Expand Up @@ -41,6 +41,7 @@ class MockView : public ReflMainView
MOCK_METHOD2(giveUserWarning, void(std::string, std::string));
MOCK_METHOD2(setProgressRange, void(int, int));
MOCK_METHOD1(setProgress, void(int));
MOCK_METHOD1(setTableList, void(const std::set<std::string>& tableList));
MOCK_METHOD2(setInstrumentList, void(const std::vector<std::string>& instruments, const std::string& defaultInstrument));
MOCK_METHOD1(setInstrument, void(const std::string&));
MOCK_CONST_METHOD0(getSelectedRowIndexes, std::vector<size_t>());
Expand Down
Expand Up @@ -97,21 +97,22 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);

presenter.notify(SaveFlag);
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));
AnalysisDataService::Instance().remove("TestWorkspace");
}

void testSaveAs()
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand All @@ -129,9 +130,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(mockView, askUserString(_,_,"Workspace")).Times(1).WillOnce(Return("Workspace"));
presenter.notify(SaveAsFlag);

//Check calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check that the workspace was saved
TS_ASSERT(AnalysisDataService::Instance().doesExist("Workspace"));

Expand All @@ -144,6 +142,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand All @@ -165,9 +164,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(mockView, askUserString(_,_,_)).Times(0);
presenter.notify(SaveFlag);

//Check calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check that the workspace was saved
TS_ASSERT(AnalysisDataService::Instance().doesExist("Workspace"));

Expand All @@ -180,6 +176,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand All @@ -206,9 +203,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits "save"
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check that the table has been modified correctly
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->rowCount(), 6);
Expand All @@ -228,6 +222,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand Down Expand Up @@ -259,9 +254,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits "save"
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check that the table has been modified correctly
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->rowCount(), 6);
Expand All @@ -283,6 +275,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand Down Expand Up @@ -316,9 +309,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits "save"
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check that the table was modified correctly
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->rowCount(), 5);
Expand All @@ -340,6 +330,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand All @@ -362,9 +353,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits save
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check that the table was not modified
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->rowCount(), 4);
Expand All @@ -379,6 +367,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand All @@ -404,9 +393,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits "save"
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->rowCount(), 3);
TS_ASSERT_EQUALS(ws->String(1, RunCol), "13469");
Expand All @@ -421,6 +407,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand Down Expand Up @@ -448,9 +435,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits save
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check the rows were deleted as expected
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->rowCount(), 1);
Expand All @@ -468,6 +452,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

createPrefilledWorkspace("TestWorkspace");
Expand All @@ -488,9 +473,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(mockView, setProgress(_)).Times(4);
presenter.notify(ProcessFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check output workspaces were created as expected
TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_13460"));
TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsLam_13460"));
Expand Down Expand Up @@ -537,6 +519,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite

MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
Expand All @@ -555,9 +538,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(mockView, setProgress(_)).Times(4);
presenter.notify(ProcessFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check output workspaces were created as expected
TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_dataA"));
TS_ASSERT(AnalysisDataService::Instance().doesExist("IvsQ_13462"));
Expand Down Expand Up @@ -591,6 +571,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite

MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
Expand All @@ -612,9 +593,6 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
//The user hits the "save" button
presenter.notify(SaveFlag);

//Check the calls were made as expected
TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView));

//Check the table was updated as expected
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->String(0, ThetaCol), "0.7");
Expand Down Expand Up @@ -656,6 +634,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite

MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

//We should receive an error
Expand All @@ -671,6 +650,7 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
{
MockView mockView;
EXPECT_CALL(mockView, setInstrumentList(_,_)).Times(1);
EXPECT_CALL(mockView, setTableList(_)).Times(AnyNumber());
ReflMainViewPresenter presenter(&mockView);

//Because we to open twice, get an error twice
Expand Down

0 comments on commit acc0692

Please sign in to comment.