/** * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ public function testSaveWithException() { $this->agreementMock->expects($this->exactly(2))->method('getAgreementId')->willReturn(null); $this->agrFactoryMock->expects($this->never())->method('create'); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getId')->willReturn('storeId'); $this->agreementMock->expects($this->once())->method('setStores'); $this->resourceMock->expects($this->once())->method('save')->with($this->agreementMock)->willThrowException(new \Exception()); $this->model->save($this->agreementMock); }