1111
1212#include < functional>
1313#include " fakeit/Sequence.hpp"
14- #include " fakeit/DomainObjects.hpp"
1514#include " mockutils/Formatter.hpp"
1615
1716namespace fakeit {
1817
19- class FakeitException {
20- };
18+ struct FakeitException {
2119
22- struct UnexpectedMethodCallException : public FakeitException {
23- UnexpectedMethodCallException () {
24- }
20+ virtual std::string what () const = 0;
2521
26- friend std::ostream & operator <<(std::ostream &os, const UnexpectedMethodCallException & val) {
27- os << std::string ( " UnexpectedMethodCallException: could not find any recorded behavior to support this method call " );
22+ friend std::ostream & operator <<(std::ostream &os, const FakeitException & val) {
23+ os << val. what ( );
2824 return os;
2925 }
26+ };
3027
28+ struct UnexpectedMethodCallException : public FakeitException {
29+ virtual std::string what () const override {
30+ return std::string (" UnexpectedMethodCallException: could not find any recorded behavior to support this method call" );
31+ }
3132};
3233
3334enum class VerificationType {
3435 Exact, AtLeast, NoMoreInvocatoins
3536};
3637
3738struct VerificationException : public FakeitException {
38-
39- VerificationException () {
40- }
41-
4239 virtual VerificationType verificationType () const = 0;
4340};
4441
@@ -61,10 +58,9 @@ struct NoMoreInvocationsVerificationException: public VerificationException {
6158 return _unverifedIvocations;
6259 }
6360
64- friend std::ostream & operator <<(std::ostream &os, const NoMoreInvocationsVerificationException& val) {
65- os << std::string (" VerificationException: expected no more invocations but found " ) //
66- .append (std::to_string (val.unverifedIvocations ().size ()));
67- return os;
61+ virtual std::string what () const override {
62+ return std::string (" VerificationException: expected no more invocations but found " ) //
63+ .append (std::to_string (unverifedIvocations ().size ()));
6864 }
6965
7066private:
@@ -103,13 +99,12 @@ struct SequenceVerificationException: public VerificationException {
10399 return _actualCount;
104100 }
105101
106- friend std::ostream & operator <<(std::ostream &os, const SequenceVerificationException& val) {
107- os << std::string (" VerificationException: expected " ) //
108- .append (val. verificationType () == fakeit::VerificationType::Exact ? " exactly " : " at least " ) //
109- .append (std::to_string (val. expectedCount ())) //
102+ virtual std::string what () const override {
103+ return std::string (" VerificationException: expected " ) //
104+ .append (verificationType () == fakeit::VerificationType::Exact ? " exactly " : " at least " ) //
105+ .append (std::to_string (expectedCount ())) //
110106 .append (" invocations but was " ) //
111- .append (std::to_string (val.actualCount ()));
112- return os;
107+ .append (std::to_string (actualCount ()));
113108 }
114109
115110private:
@@ -119,7 +114,5 @@ struct SequenceVerificationException: public VerificationException {
119114 const int _actualCount;
120115};
121116
122-
123-
124117}
125118#endif // FakeitExceptions_h__
0 commit comments