|
| 1 | +package org.mobilitydata.gtfsvalidator.validator; |
| 2 | + |
| 3 | +import static com.google.common.truth.Truth.assertThat; |
| 4 | + |
| 5 | +import java.util.Locale; |
| 6 | +import org.junit.Test; |
| 7 | +import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; |
| 8 | +import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo; |
| 9 | +import org.mobilitydata.gtfsvalidator.type.GtfsDate; |
| 10 | + |
| 11 | +public class FeedContactValidatorTest { |
| 12 | + public static GtfsFeedInfo createFeedInfo( |
| 13 | + int csvRowNumber, |
| 14 | + String feedPublisherName, |
| 15 | + String feedPublisherUrl, |
| 16 | + Locale feedLang, |
| 17 | + Locale defaultLang, |
| 18 | + GtfsDate feedStartDate, |
| 19 | + GtfsDate feedEndDate, |
| 20 | + String feedVersion, |
| 21 | + String feedContactEmail, |
| 22 | + String feedContactUrl) { |
| 23 | + return new GtfsFeedInfo.Builder() |
| 24 | + .setCsvRowNumber(csvRowNumber) |
| 25 | + .setFeedPublisherName(feedPublisherName) |
| 26 | + .setFeedPublisherUrl(feedPublisherUrl) |
| 27 | + .setFeedLang(feedLang) |
| 28 | + .setDefaultLang(defaultLang) |
| 29 | + .setFeedStartDate(feedStartDate) |
| 30 | + .setFeedEndDate(feedEndDate) |
| 31 | + .setFeedVersion(feedVersion) |
| 32 | + .setFeedContactEmail(feedContactEmail) |
| 33 | + .setFeedContactUrl(feedContactUrl) |
| 34 | + .build(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * This method is to test the case that a feed has both email and url contact information No |
| 39 | + * FeedContactNotice should be generated |
| 40 | + */ |
| 41 | + @Test |
| 42 | + public void hasFeedContactEmailAndUrlShouldNotGenerateNotice() { |
| 43 | + NoticeContainer noticeContainer = new NoticeContainer(); |
| 44 | + GtfsFeedInfo entity = |
| 45 | + createFeedInfo( |
| 46 | + 2, |
| 47 | + "feed publisher name value", |
| 48 | + "feed publisher url value", |
| 49 | + GtfsFeedInfo.DEFAULT_FEED_LANG, |
| 50 | + GtfsFeedInfo.DEFAULT_DEFAULT_LANG, |
| 51 | + GtfsFeedInfo.DEFAULT_FEED_START_DATE, |
| 52 | + GtfsFeedInfo.DEFAULT_FEED_END_DATE, |
| 53 | + GtfsFeedInfo.DEFAULT_FEED_VERSION, |
| 54 | + |
| 55 | + "https://github.com/MobilityData/gtfs-validator"); |
| 56 | + |
| 57 | + FeedContactValidator underTest = new FeedContactValidator(); |
| 58 | + underTest.validate(entity, noticeContainer); |
| 59 | + assertThat(noticeContainer.getValidationNotices()).isEmpty(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * This method is to test the case that a feed has email contact information but no contact url |
| 64 | + * information No FeedContactNotice should be generated |
| 65 | + */ |
| 66 | + @Test |
| 67 | + public void hasFeedContactEmailNoUrlShouldNotGenerateNotice1() { |
| 68 | + NoticeContainer noticeContainer = new NoticeContainer(); |
| 69 | + GtfsFeedInfo entity = |
| 70 | + createFeedInfo( |
| 71 | + 2, |
| 72 | + "feed publisher name value", |
| 73 | + "feed publisher url value", |
| 74 | + GtfsFeedInfo.DEFAULT_FEED_LANG, |
| 75 | + GtfsFeedInfo.DEFAULT_DEFAULT_LANG, |
| 76 | + GtfsFeedInfo.DEFAULT_FEED_START_DATE, |
| 77 | + GtfsFeedInfo.DEFAULT_FEED_END_DATE, |
| 78 | + GtfsFeedInfo.DEFAULT_FEED_VERSION, |
| 79 | + |
| 80 | + ""); |
| 81 | + |
| 82 | + FeedContactValidator underTest = new FeedContactValidator(); |
| 83 | + underTest.validate(entity, noticeContainer); |
| 84 | + assertThat(noticeContainer.getValidationNotices()).isEmpty(); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * This method is to test the case that a feed has email contact information but no contact url |
| 89 | + * information No FeedContactNotice should be generated |
| 90 | + */ |
| 91 | + @Test |
| 92 | + public void hasFeedContactEmailNoUrlShouldNotGenerateNotice2() { |
| 93 | + NoticeContainer noticeContainer = new NoticeContainer(); |
| 94 | + GtfsFeedInfo entity = |
| 95 | + createFeedInfo( |
| 96 | + 2, |
| 97 | + "feed publisher name value", |
| 98 | + "feed publisher url value", |
| 99 | + GtfsFeedInfo.DEFAULT_FEED_LANG, |
| 100 | + GtfsFeedInfo.DEFAULT_DEFAULT_LANG, |
| 101 | + GtfsFeedInfo.DEFAULT_FEED_START_DATE, |
| 102 | + GtfsFeedInfo.DEFAULT_FEED_END_DATE, |
| 103 | + GtfsFeedInfo.DEFAULT_FEED_VERSION, |
| 104 | + |
| 105 | + null); |
| 106 | + |
| 107 | + FeedContactValidator underTest = new FeedContactValidator(); |
| 108 | + underTest.validate(entity, noticeContainer); |
| 109 | + assertThat(noticeContainer.getValidationNotices()).isEmpty(); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * This method is to test the case that a feed has contact url but no contact email No |
| 114 | + * FeedContactNotice should be generated |
| 115 | + */ |
| 116 | + @Test |
| 117 | + public void hasFeedContactUrlNoEmailShouldNotGenerateNotice1() { |
| 118 | + NoticeContainer noticeContainer = new NoticeContainer(); |
| 119 | + GtfsFeedInfo entity = |
| 120 | + createFeedInfo( |
| 121 | + 2, |
| 122 | + "feed publisher name value", |
| 123 | + "feed publisher url value", |
| 124 | + GtfsFeedInfo.DEFAULT_FEED_LANG, |
| 125 | + GtfsFeedInfo.DEFAULT_DEFAULT_LANG, |
| 126 | + GtfsFeedInfo.DEFAULT_FEED_START_DATE, |
| 127 | + GtfsFeedInfo.DEFAULT_FEED_END_DATE, |
| 128 | + GtfsFeedInfo.DEFAULT_FEED_VERSION, |
| 129 | + "", |
| 130 | + "https://github.com/MobilityData/gtfs-validator"); |
| 131 | + |
| 132 | + FeedContactValidator underTest = new FeedContactValidator(); |
| 133 | + underTest.validate(entity, noticeContainer); |
| 134 | + assertThat(noticeContainer.getValidationNotices()).isEmpty(); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * This method is to test the case that a feed has contact url but no contact email No |
| 139 | + * FeedContactNotice should be generated |
| 140 | + */ |
| 141 | + @Test |
| 142 | + public void hasFeedContactUrlNoEmailShouldNotGenerateNotice2() { |
| 143 | + NoticeContainer noticeContainer = new NoticeContainer(); |
| 144 | + GtfsFeedInfo entity = |
| 145 | + createFeedInfo( |
| 146 | + 2, |
| 147 | + "feed publisher name value", |
| 148 | + "feed publisher url value", |
| 149 | + GtfsFeedInfo.DEFAULT_FEED_LANG, |
| 150 | + GtfsFeedInfo.DEFAULT_DEFAULT_LANG, |
| 151 | + GtfsFeedInfo.DEFAULT_FEED_START_DATE, |
| 152 | + GtfsFeedInfo.DEFAULT_FEED_END_DATE, |
| 153 | + GtfsFeedInfo.DEFAULT_FEED_VERSION, |
| 154 | + null, |
| 155 | + "https://github.com/MobilityData/gtfs-validator"); |
| 156 | + |
| 157 | + FeedContactValidator underTest = new FeedContactValidator(); |
| 158 | + underTest.validate(entity, noticeContainer); |
| 159 | + assertThat(noticeContainer.getValidationNotices()).isEmpty(); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * This method is to test the case that a feed has neither contact url nor contact email |
| 164 | + * FeedContactNotice should be generated |
| 165 | + */ |
| 166 | + @Test |
| 167 | + public void nonFeedContactEmailAndUrlShouldGenerateNotice() { |
| 168 | + NoticeContainer noticeContainer = new NoticeContainer(); |
| 169 | + GtfsFeedInfo entity = |
| 170 | + createFeedInfo( |
| 171 | + 2, |
| 172 | + "feed publisher name value", |
| 173 | + "feed publisher url value", |
| 174 | + GtfsFeedInfo.DEFAULT_FEED_LANG, |
| 175 | + GtfsFeedInfo.DEFAULT_DEFAULT_LANG, |
| 176 | + GtfsFeedInfo.DEFAULT_FEED_START_DATE, |
| 177 | + GtfsFeedInfo.DEFAULT_FEED_END_DATE, |
| 178 | + GtfsFeedInfo.DEFAULT_FEED_VERSION, |
| 179 | + "", |
| 180 | + ""); |
| 181 | + |
| 182 | + FeedContactValidator underTest = new FeedContactValidator(); |
| 183 | + underTest.validate(entity, noticeContainer); |
| 184 | + assertThat(noticeContainer.getValidationNotices()) |
| 185 | + .containsExactly(new FeedContactValidator.FeedContactNotice(2, "", "")); |
| 186 | + } |
| 187 | +} |
0 commit comments