|
10 | 10 | import com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir.customsuffix.subdir.ImplementationClassWithWrongTestClassPackageCustomSuffixTestingScenario; |
11 | 11 | import com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir.defaultsuffix.ImplementationClassWithWrongTestClassPackage; |
12 | 12 | import com.tngtech.archunit.library.testclasses.packages.incorrect.wrongsubdir.defaultsuffix.subdir.ImplementationClassWithWrongTestClassPackageTest; |
| 13 | +import com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaSqlDate; |
| 14 | +import com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaSqlTime; |
| 15 | +import com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaSqlTimestamp; |
| 16 | +import com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilCalender; |
| 17 | +import com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate; |
13 | 18 | import org.junit.Test; |
14 | 19 |
|
15 | 20 | import static com.tngtech.archunit.core.domain.JavaConstructor.CONSTRUCTOR_NAME; |
16 | 21 | import static com.tngtech.archunit.library.GeneralCodingRules.ASSERTIONS_SHOULD_HAVE_DETAIL_MESSAGE; |
17 | 22 | import static com.tngtech.archunit.library.GeneralCodingRules.DEPRECATED_API_SHOULD_NOT_BE_USED; |
| 23 | +import static com.tngtech.archunit.library.GeneralCodingRules.OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED; |
18 | 24 | import static com.tngtech.archunit.library.GeneralCodingRules.testClassesShouldResideInTheSamePackageAsImplementation; |
19 | 25 | import static com.tngtech.archunit.testutil.Assertions.assertThatRule; |
20 | 26 |
|
@@ -180,4 +186,44 @@ void origin() { |
180 | 186 | @SuppressWarnings("DeprecatedIsStillUsed") |
181 | 187 | private @interface DeprecatedAnnotation { |
182 | 188 | } |
| 189 | + |
| 190 | + @Test |
| 191 | + public void OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_util_date() { |
| 192 | + assertThatRule(OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED) |
| 193 | + .hasDescription("java.time API should be used, because legacy date/time APIs have been replaced since Java 8 (JSR 310)") |
| 194 | + .checking(new ClassFileImporter().importClasses(UsesJavaUtilDate.class)) |
| 195 | + .hasViolationContaining("calls method <java.util.Date"); |
| 196 | + } |
| 197 | + |
| 198 | + @Test |
| 199 | + public void OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_sql_timestamp() { |
| 200 | + assertThatRule(OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED) |
| 201 | + .hasDescription("java.time API should be used, because legacy date/time APIs have been replaced since Java 8 (JSR 310)") |
| 202 | + .checking(new ClassFileImporter().importClasses(UsesJavaSqlTimestamp.class)) |
| 203 | + .hasViolationContaining("calls constructor <java.sql.Timestamp"); |
| 204 | + } |
| 205 | + |
| 206 | + @Test |
| 207 | + public void OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_sql_time() { |
| 208 | + assertThatRule(OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED) |
| 209 | + .hasDescription("java.time API should be used, because legacy date/time APIs have been replaced since Java 8 (JSR 310)") |
| 210 | + .checking(new ClassFileImporter().importClasses(UsesJavaSqlTime.class)) |
| 211 | + .hasViolationContaining("calls constructor <java.sql.Time"); |
| 212 | + } |
| 213 | + |
| 214 | + @Test |
| 215 | + public void OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_sql_date() { |
| 216 | + assertThatRule(OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED) |
| 217 | + .hasDescription("java.time API should be used, because legacy date/time APIs have been replaced since Java 8 (JSR 310)") |
| 218 | + .checking(new ClassFileImporter().importClasses(UsesJavaSqlDate.class)) |
| 219 | + .hasViolationContaining("calls constructor <java.sql.Date"); |
| 220 | + } |
| 221 | + |
| 222 | + @Test |
| 223 | + public void OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_util_calender() { |
| 224 | + assertThatRule(OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED) |
| 225 | + .hasDescription("java.time API should be used, because legacy date/time APIs have been replaced since Java 8 (JSR 310)") |
| 226 | + .checking(new ClassFileImporter().importClasses(UsesJavaUtilCalender.class)) |
| 227 | + .hasViolationContaining("calls method <java.util.Calendar"); |
| 228 | + } |
183 | 229 | } |
0 commit comments