{"id":312973,"date":"2020-11-11T21:00:22","date_gmt":"2020-11-11T21:00:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=312973"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=312973","title":{"rendered":"\u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043f\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043a\u043e\u0434\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c ArchUnit"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435 \u043c\u044b, \u043a\u0430\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u0441\u043e\u0433\u043b\u0430\u0448\u0430\u0435\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438.&nbsp;\u041d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u043e \u043d\u0435\u0437\u043d\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u043d\u0435\u0436\u0435\u043b\u0430\u043d\u0438\u044e.&nbsp;\u041e\u0431\u044b\u0447\u043d\u043e \u043c\u044b \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f \u043d\u0430&nbsp;<strong>\u0440\u0435\u0432\u044c\u044e \u043a\u043e\u0434\u0430<\/strong>&nbsp;\u0438\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a&nbsp;<strong>SonarQube<\/strong>&nbsp;,&nbsp;<strong>PMD \u0438<\/strong>&nbsp;\u0442.\u0434. \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0430\u043a\u0438\u0445 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0439.&nbsp;\u041d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SonarQube, PMD \u0438 \u0442.\u0434.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044b\u0447\u043d\u043e \u044f \u0445\u043e\u0447\u0443 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c \u0434\u043b\u044f \u043c\u043e\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Java:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u043b\u0435\u0434\u0443\u0439\u0442\u0435 \u0442\u0440\u0435\u0445\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435<\/strong>&nbsp;(\u0443\u0440\u043e\u0432\u043d\u0438 \u0432\u0435\u0431, \u0441\u0435\u0440\u0432\u0438\u0441, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439), \u0433\u0434\u0435 \u043b\u044e\u0431\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c, \u0430 \u043d\u0438\u0436\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0435\u0440\u0445\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c.&nbsp;\u0442.\u0435. \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u041d\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u043c \u0438\u043b\u0438 \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u043d\u0435\u043c, \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u043d\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c  \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <strong>Package-By-Feature,<\/strong> \u0433\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b Web \u0438 Service \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f public, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c package-private. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 Spring <strong>\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u044f<\/strong> \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c. \u0425\u043e\u0440\u043e\u0448\u0430\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f  \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e  JUnit \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <em><u>ArchUnit<\/u><\/em>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b6\/9d0\/c9f\/3b69d0c9f45658a0b64da7cb07e0b7ec.png\" width=\"804\" height=\"141\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c <em><u>\u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e <\/u><\/em><a href=\"https:\/\/www.archunit.org\/userguide\/html\/000_Index.html\" rel=\"noopener noreferrer nofollow\"><em><u>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f ArchUnit<\/u><\/em><\/a><em><u>.<\/u><\/em><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ArchUnit \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043f\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <strong>archunit-junit5<\/strong>.<\/p>\n<pre><code class=\"xml\">&lt;dependency&gt;     &lt;groupId&gt;com.tngtech.archunit&lt;\/groupId&gt;     &lt;artifactId&gt;archunit-junit5&lt;\/artifactId&gt;     &lt;version&gt;0.13.1&lt;\/version&gt;     &lt;scope&gt;test&lt;\/scope&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0432\u044b\u0448\u0435.<\/p>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 1. \u0421\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u043d\u0435\u043c.<\/h4>\n<pre><code class=\"java\">package com.sivalabs.moviebuffs;  import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.core.importer.ClassFileImporter; import com.tngtech.archunit.core.importer.ImportOption; import org.junit.jupiter.api.Test; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*; import static com.tngtech.archunit.library.Architectures.layeredArchitecture;  class ArchTest {      @Test     void servicesAndRepositoriesShouldNotDependOnWebLayer() {       JavaClasses importedClasses = new ClassFileImporter()           .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)           .importPackages(\"com.sivalabs.moviebuffs\");        noClasses()           .that().resideInAnyPackage(\"com.sivalabs.moviebuffs.core.service..\")             .or().resideInAnyPackage(\"com.sivalabs.moviebuffs.core.repository..\")           .should()             .dependOnClassesThat()             .resideInAnyPackage(\"com.sivalabs.moviebuffs.web..\")           .because(\"Services and repositories should not depend on web layer\")           .check(importedClasses);     } }<\/code><\/pre>\n<p>ArchUnit \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 DSL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0446\u0435\u043b\u044c \u0442\u0435\u0441\u0442\u0430.&nbsp;\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c.<\/p>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 2: \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b<\/h4>\n<p>\u0412 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 SpringBoot&nbsp;\u0443\u0440\u043e\u0432\u0435\u043d\u044c&nbsp;<strong>\u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/strong> \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0443\u0440\u043e\u0432\u043d\u044f <strong>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/strong>, \u0430 \u0443\u0440\u043e\u0432\u043d\u0438 <strong>\u0432\u0435\u0431<\/strong>&nbsp;\u0438&nbsp;<strong>\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/strong> \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0443\u0440\u043e\u0432\u043d\u044f <strong>\u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/strong>. <strong>\u041c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0443\u0440\u043e\u0432\u0435\u043d\u044c Web \u0438\u043b\u0438 Config \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/strong><\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<pre><code class=\"java\">@Test void shouldFollowLayeredArchitecture() {   JavaClasses importedClasses = new ClassFileImporter()           .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)           .importPackages(\"com.sivalabs.moviebuffs\");    layeredArchitecture()       .layer(\"Web\").definedBy(\"..web..\")       .layer(\"Config\").definedBy(\"..config..\")       .layer(\"Service\").definedBy(\"..service..\")       .layer(\"Persistence\").definedBy(\"..repository..\")        .whereLayer(\"Web\").mayNotBeAccessedByAnyLayer()       .whereLayer(\"Service\").mayOnlyBeAccessedByLayers(\"Config\", \"Web\")       .whereLayer(\"Persistence\").mayOnlyBeAccessedByLayers(\"Service\")       .check(importedClasses); }<\/code><\/pre>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 3: Spring @Autowired \u041d\u0415 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u044f<\/h4>\n<pre><code>@Test void shouldNotUseFieldInjection() {     JavaClasses importedClasses = new ClassFileImporter()           .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)           .importPackages(\"com.sivalabs.moviebuffs\");      noFields()       .should().beAnnotatedWith(Autowired.class)       .check(importedClasses); }<\/code><\/pre>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 4: \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435 \u043e\u0431 \u0438\u043c\u0435\u043d\u0430\u0445<\/h4>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f\u043c \u043e\u0431 \u0438\u043c\u0435\u043d\u0430\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430&nbsp;<strong>Service<\/strong>&nbsp;\u0438 \u0442.\u0434.<\/p>\n<pre><code class=\"java\">@Test void shouldFollowNamingConvention() {     JavaClasses importedClasses = new ClassFileImporter()         .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)         .importPackages(\"com.sivalabs.moviebuffs\");     classes()         .that().resideInAPackage(\"com.sivalabs.moviebuffs.core.repository\")         .should().haveSimpleNameEndingWith(\"Repository\")         .check(importedClasses);      classes()         .that().resideInAPackage(\"com.sivalabs.moviebuffs.core.service\")         .should().haveSimpleNameEndingWith(\"Service\")         .check(importedClasses); }<\/code><\/pre>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 5: \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e JUnit 5<\/h4>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c&nbsp;<strong>JUnit 5 \u0432<\/strong>&nbsp;\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0448\u0435\u0439 \u0441\u0440\u0435\u0434\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.&nbsp;\u041d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c JUnit 4 \u043c\u043e\u0433\u043b\u0430 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043f\u0443\u0442\u044c \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043a\u0430\u043a \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c (\u0445\u043c\u2026&nbsp;<strong>Testcontainers<\/strong>&nbsp;\u2026 \u0445\u043c), \u0438 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b\/\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438&nbsp;<strong>JUnit4<\/strong>&nbsp;,&nbsp;\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a&nbsp;<strong>@Test<\/strong>&nbsp;,&nbsp;<strong>Assert \u0438<\/strong> \u0442.\u0434. \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 JUnit 4 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">@Test void shouldNotUseJunit4Classes() {     JavaClasses classes = new ClassFileImporter()         .importPackages(\"com.sivalabs.moviebuffs\");      noClasses()         .should().accessClassesThat().resideInAnyPackage(\"org.junit\")         .because(\"Tests should use Junit5 instead of Junit4\")         .check(classes);      noMethods().should().beAnnotatedWith(\"org.junit.Test\")         .orShould().beAnnotatedWith(\"org.junit.Ignore\")         .because(\"Tests should use Junit5 instead of Junit4\")         .check(classes); }<\/code><\/pre>\n<p>\u042f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043b \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u044f\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439&nbsp;<a href=\"https:\/\/www.archunit.org\/userguide\/html\/000_Index.html\" rel=\"noopener noreferrer nofollow\"><strong><u>ArchUnit UserGuide<\/u><\/strong><\/a>&nbsp;\u0438 \u0443\u0437\u043d\u0430\u0439\u0442\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u043a\u0440\u0443\u0442\u044b\u0435 \u0432\u0435\u0449\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441&nbsp;<strong>ArchUnit<\/strong>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/527618\/\"> https:\/\/habr.com\/ru\/post\/527618\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435 \u043c\u044b, \u043a\u0430\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u0441\u043e\u0433\u043b\u0430\u0448\u0430\u0435\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438.&nbsp;\u041d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u043e \u043d\u0435\u0437\u043d\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u043d\u0435\u0436\u0435\u043b\u0430\u043d\u0438\u044e.&nbsp;\u041e\u0431\u044b\u0447\u043d\u043e \u043c\u044b \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f \u043d\u0430&nbsp;<strong>\u0440\u0435\u0432\u044c\u044e \u043a\u043e\u0434\u0430<\/strong>&nbsp;\u0438\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a&nbsp;<strong>SonarQube<\/strong>&nbsp;,&nbsp;<strong>PMD \u0438<\/strong>&nbsp;\u0442.\u0434. \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0430\u043a\u0438\u0445 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0439.&nbsp;\u041d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SonarQube, PMD \u0438 \u0442.\u0434.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044b\u0447\u043d\u043e \u044f \u0445\u043e\u0447\u0443 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c \u0434\u043b\u044f \u043c\u043e\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Java:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u043b\u0435\u0434\u0443\u0439\u0442\u0435 \u0442\u0440\u0435\u0445\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435<\/strong>&nbsp;(\u0443\u0440\u043e\u0432\u043d\u0438 \u0432\u0435\u0431, \u0441\u0435\u0440\u0432\u0438\u0441, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439), \u0433\u0434\u0435 \u043b\u044e\u0431\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c, \u0430 \u043d\u0438\u0436\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0435\u0440\u0445\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c.&nbsp;\u0442.\u0435. \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u041d\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u043c \u0438\u043b\u0438 \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u043d\u0435\u043c, \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u043d\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c  \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <strong>Package-By-Feature,<\/strong> \u0433\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b Web \u0438 Service \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f public, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c package-private. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 Spring <strong>\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u044f<\/strong> \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c. \u0425\u043e\u0440\u043e\u0448\u0430\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f  \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e  JUnit \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <em><u>ArchUnit<\/u><\/em>.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c <em><u>\u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e <\/u><\/em><a href=\"https:\/\/www.archunit.org\/userguide\/html\/000_Index.html\" rel=\"noopener noreferrer nofollow\"><em><u>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f ArchUnit<\/u><\/em><\/a><em><u>.<\/u><\/em><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ArchUnit \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043f\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <strong>archunit-junit5<\/strong>.<\/p>\n<pre><code class=\"xml\">&lt;dependency&gt;     &lt;groupId&gt;com.tngtech.archunit&lt;\/groupId&gt;     &lt;artifactId&gt;archunit-junit5&lt;\/artifactId&gt;     &lt;version&gt;0.13.1&lt;\/version&gt;     &lt;scope&gt;test&lt;\/scope&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0432\u044b\u0448\u0435.<\/p>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 1. \u0421\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0435\u0431-\u0443\u0440\u043e\u0432\u043d\u0435\u043c.<\/h4>\n<pre><code class=\"java\">package com.sivalabs.moviebuffs;  import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.core.importer.ClassFileImporter; import com.tngtech.archunit.core.importer.ImportOption; import org.junit.jupiter.api.Test; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*; import static com.tngtech.archunit.library.Architectures.layeredArchitecture;  class ArchTest {      @Test     void servicesAndRepositoriesShouldNotDependOnWebLayer() {       JavaClasses importedClasses = new ClassFileImporter()           .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)           .importPackages(\"com.sivalabs.moviebuffs\");        noClasses()           .that().resideInAnyPackage(\"com.sivalabs.moviebuffs.core.service..\")             .or().resideInAnyPackage(\"com.sivalabs.moviebuffs.core.repository..\")           .should()             .dependOnClassesThat()             .resideInAnyPackage(\"com.sivalabs.moviebuffs.web..\")           .because(\"Services and repositories should not depend on web layer\")           .check(importedClasses);     } }<\/code><\/pre>\n<p>ArchUnit \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 DSL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0446\u0435\u043b\u044c \u0442\u0435\u0441\u0442\u0430.&nbsp;\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c.<\/p>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 2: \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b<\/h4>\n<p>\u0412 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 SpringBoot&nbsp;\u0443\u0440\u043e\u0432\u0435\u043d\u044c&nbsp;<strong>\u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/strong> \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0443\u0440\u043e\u0432\u043d\u044f <strong>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/strong>, \u0430 \u0443\u0440\u043e\u0432\u043d\u0438 <strong>\u0432\u0435\u0431<\/strong>&nbsp;\u0438&nbsp;<strong>\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/strong> \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0443\u0440\u043e\u0432\u043d\u044f <strong>\u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/strong>. <strong>\u041c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0443\u0440\u043e\u0432\u0435\u043d\u044c Web \u0438\u043b\u0438 Config \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/strong><\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<pre><code class=\"java\">@Test void shouldFollowLayeredArchitecture() {   JavaClasses importedClasses = new ClassFileImporter()           .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)           .importPackages(\"com.sivalabs.moviebuffs\");    layeredArchitecture()       .layer(\"Web\").definedBy(\"..web..\")       .layer(\"Config\").definedBy(\"..config..\")       .layer(\"Service\").definedBy(\"..service..\")       .layer(\"Persistence\").definedBy(\"..repository..\")        .whereLayer(\"Web\").mayNotBeAccessedByAnyLayer()       .whereLayer(\"Service\").mayOnlyBeAccessedByLayers(\"Config\", \"Web\")       .whereLayer(\"Persistence\").mayOnlyBeAccessedByLayers(\"Service\")       .check(importedClasses); }<\/code><\/pre>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 3: Spring @Autowired \u041d\u0415 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u044f<\/h4>\n<pre><code>@Test void shouldNotUseFieldInjection() {     JavaClasses importedClasses = new ClassFileImporter()           .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)           .importPackages(\"com.sivalabs.moviebuffs\");      noFields()       .should().beAnnotatedWith(Autowired.class)       .check(importedClasses); }<\/code><\/pre>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 4: \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435 \u043e\u0431 \u0438\u043c\u0435\u043d\u0430\u0445<\/h4>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f\u043c \u043e\u0431 \u0438\u043c\u0435\u043d\u0430\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430&nbsp;<strong>Service<\/strong>&nbsp;\u0438 \u0442.\u0434.<\/p>\n<pre><code class=\"java\">@Test void shouldFollowNamingConvention() {     JavaClasses importedClasses = new ClassFileImporter()         .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)         .importPackages(\"com.sivalabs.moviebuffs\");     classes()         .that().resideInAPackage(\"com.sivalabs.moviebuffs.core.repository\")         .should().haveSimpleNameEndingWith(\"Repository\")         .check(importedClasses);      classes()         .that().resideInAPackage(\"com.sivalabs.moviebuffs.core.service\")         .should().haveSimpleNameEndingWith(\"Service\")         .check(importedClasses); }<\/code><\/pre>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 5: \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e JUnit 5<\/h4>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c&nbsp;<strong>JUnit 5 \u0432<\/strong>&nbsp;\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0448\u0435\u0439 \u0441\u0440\u0435\u0434\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.&nbsp;\u041d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c JUnit 4 \u043c\u043e\u0433\u043b\u0430 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043f\u0443\u0442\u044c \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043a\u0430\u043a \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0438\u0432\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c (\u0445\u043c\u2026&nbsp;<strong>Testcontainers<\/strong>&nbsp;\u2026 \u0445\u043c), \u0438 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b\/\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438&nbsp;<strong>JUnit4<\/strong>&nbsp;,&nbsp;\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a&nbsp;<strong>@Test<\/strong>&nbsp;,&nbsp;<strong>Assert \u0438<\/strong> \u0442.\u0434. \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 JUnit 4 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">@Test void shouldNotUseJunit4Classes() {     JavaClasses classes = new ClassFileImporter()         .importPackages(\"com.sivalabs.moviebuffs\");      noClasses()         .should().accessClassesThat().resideInAnyPackage(\"org.junit\")         .because(\"Tests should use Junit5 instead of Junit4\")         .check(classes);      noMethods().should().beAnnotatedWith(\"org.junit.Test\")         .orShould().beAnnotatedWith(\"org.junit.Ignore\")         .because(\"Tests should use Junit5 instead of Junit4\")         .check(classes); }<\/code><\/pre>\n<p>\u042f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043b \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u044f\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439&nbsp;<a href=\"https:\/\/www.archunit.org\/userguide\/html\/000_Index.html\" rel=\"noopener noreferrer nofollow\"><strong><u>ArchUnit UserGuide<\/u><\/strong><\/a>&nbsp;\u0438 \u0443\u0437\u043d\u0430\u0439\u0442\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u043a\u0440\u0443\u0442\u044b\u0435 \u0432\u0435\u0449\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441&nbsp;<strong>ArchUnit<\/strong>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/527618\/\"> https:\/\/habr.com\/ru\/post\/527618\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-312973","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=312973"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312973\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}