File tree Expand file tree Collapse file tree 4 files changed +80
-2
lines changed
interfaces/include/interfaces/parsers Expand file tree Collapse file tree 4 files changed +80
-2
lines changed Original file line number Diff line number Diff line change 5
5
#ifndef DESIGN_PATTERNS_IPARSERSFACTORY_H
6
6
#define DESIGN_PATTERNS_IPARSERSFACTORY_H
7
7
8
+ #include < memory>
9
+ #include " parsers/ICredentialsParser.h"
10
+ #include " parsers/IReportParser.h"
11
+
12
+ namespace parsers
13
+ {
14
+ class IParserFactory
15
+ {
16
+ public:
17
+ virtual ~IParserFactory () = default ;
18
+
19
+ virtual std::unique_ptr<IReportParser> createReportParser () const = 0;
20
+
21
+ virtual std::unique_ptr<ICredentialsParser> createCredentialParser () const = 0;
22
+
23
+ };
24
+ }
25
+
26
+
8
27
#endif // DESIGN_PATTERNS_IPARSERSFACTORY_H
Original file line number Diff line number Diff line change 5
5
#ifndef DESIGN_PATTERNS_PARSERSFACTORY_H
6
6
#define DESIGN_PATTERNS_PARSERSFACTORY_H
7
7
8
+ #include " parsers/IParsersFactory.h"
9
+ #include < memory>
10
+ #include " types/ReportFormat.h"
11
+
12
+ namespace parsers
13
+ {
14
+ class ParserFactory : public IParserFactory
15
+ {
16
+ public:
17
+ ParserFactory (const types::ReportFormat);
18
+
19
+ std::unique_ptr<IReportParser> createReportParser () const override ;
20
+
21
+ std::unique_ptr<ICredentialsParser> createCredentialParser () const override ;
22
+
23
+ private:
24
+ const types::ReportFormat reportFormat;
25
+ };
26
+ }
27
+
28
+
8
29
#endif // DESIGN_PATTERNS_PARSERSFACTORY_H
Original file line number Diff line number Diff line change 5
5
#include " parsers/ParsersFactory.h"
6
6
#include " parsers/JsonParser.h"
7
7
#include " parsers/ValidatedReportParser.h"
8
- #include " parsers/XmlParser.h"
8
+ #include " parsers/XmlParser.h"
9
+
10
+ namespace parsers
11
+ {
12
+ ParserFactory::ParserFactory (const types::ReportFormat rF) : reportFormat{rF} {}
13
+
14
+ std::unique_ptr<IReportParser> ParserFactory::createReportParser () const
15
+ {
16
+ switch (reportFormat)
17
+ {
18
+ case types::ReportFormat::Json:
19
+ return std::make_unique<parsers::ValidatedReportParser<JsonParser>>();
20
+
21
+ case types::ReportFormat::Xml:
22
+ return std::make_unique<parsers::ValidatedReportParser<XmlParser>>();
23
+ }
24
+ return nullptr ;
25
+ }
26
+
27
+ std::unique_ptr<ICredentialsParser> ParserFactory::createCredentialParser () const
28
+ {
29
+ switch (reportFormat)
30
+ {
31
+ case types::ReportFormat::Json:
32
+ return std::make_unique<JsonParser>();
33
+ case types::ReportFormat::Xml:
34
+ return std::make_unique<XmlParser>();
35
+ }
36
+ return nullptr ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change @@ -48,6 +48,14 @@ namespace parsers
48
48
49
49
TEST_F (ValidatedReportParserTest, reportValidationSucceeds)
50
50
{
51
- // ASSERT_NE(sut.parseReport(validReport), std::nullopt);
51
+ ASSERT_NE (sut.parseReport (validReport), std::nullopt );
52
+ }
53
+
54
+ TEST_F (ValidatedReportParserTest, reportValidationFails)
55
+ {
56
+ for (const auto &item: invalidReports)
57
+ {
58
+ ASSERT_EQ (sut.parseReport (item), std::nullopt );
59
+ }
52
60
}
53
61
}
You can’t perform that action at this time.
0 commit comments