|
16 | 16 | */ |
17 | 17 | package com.google.edwmigration.dumper.application.dumper.connector; |
18 | 18 |
|
| 19 | +import static com.google.edwmigration.dumper.application.dumper.connector.Connector.validateDateRange; |
19 | 20 | import static org.junit.Assert.assertEquals; |
20 | 21 | import static org.junit.Assert.assertThrows; |
21 | 22 |
|
22 | 23 | import com.google.edwmigration.dumper.application.dumper.ConnectorArguments; |
23 | | -import com.google.edwmigration.dumper.application.dumper.handle.Handle; |
24 | | -import com.google.edwmigration.dumper.application.dumper.task.Task; |
25 | | -import java.time.Clock; |
26 | | -import java.util.List; |
27 | | -import javax.annotation.Nonnull; |
28 | 24 | import org.junit.Test; |
29 | 25 |
|
30 | 26 | public class ConnectorTest { |
31 | | - private final Connector connector = new EmptyConnector(); |
32 | 27 |
|
33 | 28 | @Test |
34 | 29 | public void validateDateRange_startDateAndEndDate_success() throws Exception { |
35 | | - String argsStr = "--connector test --start-date=2001-02-20 --end-date=2001-02-25"; |
| 30 | + ConnectorArguments args = |
| 31 | + new ConnectorArguments( |
| 32 | + "--connector", "test", "--start-date=2001-02-20", "--end-date=2001-02-25"); |
36 | 33 |
|
37 | 34 | // Act |
38 | | - connector.validateDateRange(toArgs(argsStr)); |
| 35 | + validateDateRange(args); |
39 | 36 | } |
40 | 37 |
|
41 | 38 | @Test |
42 | | - public void validateDateRange_startDateAfterEndDate_throws() { |
43 | | - String argsStr = "--connector test --start-date=2001-02-20 --end-date=2001-02-20"; |
| 39 | + public void validateDateRange_startDateAfterEndDate_throws() throws Exception { |
| 40 | + ConnectorArguments args = |
| 41 | + new ConnectorArguments( |
| 42 | + "--connector", "test", "--start-date=2001-02-20", "--end-date=2001-02-20"); |
44 | 43 |
|
45 | 44 | Exception exception = |
46 | | - assertThrows( |
47 | | - IllegalStateException.class, () -> connector.validateDateRange(toArgs(argsStr))); |
| 45 | + assertThrows(IllegalStateException.class, () -> Connector.validateDateRange(args)); |
48 | 46 | assertEquals( |
49 | 47 | "Start date [2001-02-20T00:00Z] must be before end date [2001-02-20T00:00Z].", |
50 | 48 | exception.getMessage()); |
51 | 49 | } |
52 | 50 |
|
53 | 51 | @Test |
54 | | - public void validateDateRange_endDateAlone_throws() { |
55 | | - String argsStr = "--connector test --end-date=2001-02-20"; |
| 52 | + public void validateDateRange_endDateAlone_throws() throws Exception { |
| 53 | + ConnectorArguments args = |
| 54 | + new ConnectorArguments("--connector", "test", "--end-date=2001-02-20"); |
56 | 55 |
|
57 | | - Exception exception = |
58 | | - assertThrows( |
59 | | - IllegalStateException.class, () -> connector.validateDateRange(toArgs(argsStr))); |
| 56 | + Exception exception = assertThrows(IllegalStateException.class, () -> validateDateRange(args)); |
60 | 57 | assertEquals( |
61 | 58 | "End date can be specified only with start date, but start date was null.", |
62 | 59 | exception.getMessage()); |
63 | 60 | } |
64 | 61 |
|
65 | 62 | @Test |
66 | | - public void validateDateRange_startDateAlone_throws() { |
67 | | - String argsStr = "--connector test --start-date=2001-02-20"; |
| 63 | + public void validateDateRange_startDateAlone_throws() throws Exception { |
| 64 | + ConnectorArguments args = |
| 65 | + new ConnectorArguments("--connector", "test", "--start-date=2001-02-20"); |
68 | 66 |
|
69 | | - Exception exception = |
70 | | - assertThrows(RuntimeException.class, () -> connector.validateDateRange(toArgs(argsStr))); |
| 67 | + Exception exception = assertThrows(RuntimeException.class, () -> validateDateRange(args)); |
71 | 68 | assertEquals( |
72 | 69 | "End date must be specified with start date, but was null.", exception.getMessage()); |
73 | 70 | } |
74 | 71 |
|
75 | 72 | @Test |
76 | 73 | public void validateDateRange_requiredArgs_success() throws Exception { |
77 | 74 | // Act |
78 | | - connector.validateDateRange(toArgs("--connector test")); |
79 | | - } |
80 | | - |
81 | | - private static class EmptyConnector implements Connector { |
82 | | - |
83 | | - @Nonnull |
84 | | - @Override |
85 | | - public String getName() { |
86 | | - return null; |
87 | | - } |
88 | | - |
89 | | - @Nonnull |
90 | | - @Override |
91 | | - public String getDefaultFileName(boolean isAssessment, Clock clock) { |
92 | | - return null; |
93 | | - } |
94 | | - |
95 | | - @Override |
96 | | - public void addTasksTo( |
97 | | - @Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments) |
98 | | - throws Exception {} |
99 | | - |
100 | | - @Nonnull |
101 | | - @Override |
102 | | - public Handle open(@Nonnull ConnectorArguments arguments) throws Exception { |
103 | | - return null; |
104 | | - } |
105 | | - |
106 | | - @Nonnull |
107 | | - @Override |
108 | | - public Iterable<ConnectorProperty> getPropertyConstants() { |
109 | | - return null; |
110 | | - } |
111 | | - } |
112 | | - |
113 | | - private static ConnectorArguments toArgs(String args) throws Exception { |
114 | | - return new ConnectorArguments(args.split(" ")); |
| 75 | + validateDateRange(new ConnectorArguments("--connector", "test")); |
115 | 76 | } |
116 | 77 | } |
0 commit comments