{"id":317918,"date":"2021-02-12T15:01:27","date_gmt":"2021-02-12T15:01:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=317918"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=317918","title":{"rendered":"Mockito. \u0418\u0437 \u0447\u0435\u0433\u043e \u043e\u043d \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c?"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><a href=\"https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/541762\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/da\/xr\/k6\/daxrk6esxcf6kbmnjgvxu_ytcxe.jpeg\"><\/div>\n<p><\/a><br \/>  \u0414\u0443\u043c\u0430\u044e, \u043c\u043d\u043e\u0433\u0438\u043c \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u0432\u044b\u043f\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0430\u043f\u0438\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u043f\u0438\u043b\u0441\u044f \u0432 \u043d\u0430\u0448\u0438 \u0432\u043a\u0443\u0441\u043e\u0432\u044b\u0435 \u0440\u0435\u0446\u0435\u043f\u0442\u043e\u0440\u044b, \u0447\u0442\u043e \u043d\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c. \u0422\u0430\u043a \u0432\u043e\u0442 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0442\u0430\u043a\u0438\u043c \u00ab\u043d\u0430\u043f\u0438\u0442\u043a\u043e\u043c\u00bb \u0441\u0442\u0430\u043b Mockito. \u041e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0442\u0435\u0441\u0442, \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0435\u0431\u0435 \u0432\u0435\u0440\u0443 \u0432 \u043c\u0430\u0433\u0438\u044e. \u042f \u0432\u0441\u0451 \u0435\u0449\u0451 \u043f\u043e\u043c\u043d\u044e, \u043a\u0430\u043a \u0443\u0434\u0438\u0432\u043b\u044f\u043b\u0441\u044f \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. <\/p>\n<p>  \u0427\u0435\u043c\u0443 \u0436\u0435 \u044f \u0443\u0434\u0438\u0432\u0438\u043b\u0441\u044f? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e\u043c\u0443:<\/p>\n<pre><code class=\"java\">private static class Apple {    private String color;    public String getName() {return color;} }  @Test public void basic() {    Apple apple = mock(Apple.class);    when(apple.getName()).thenReturn(&quot;Red&quot;);    assertEquals(&quot;Red&quot;, apple.getName()); \/\/ true }<\/code><\/pre>\n<p>  \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e:<\/p>\n<ul>\n<li>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440-\u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Apple.  <\/li>\n<li>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043a\u0430\u043a \u0431\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 apple.getColor(), \u0442\u043e \u0432\u0435\u0440\u043d\u0438 \u00abRed\u00bb.  <\/li>\n<li>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 apple.getColor() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!  <\/li>\n<\/ul>\n<p>  \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041d\u0435 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u0430\u043b\u044c\u0448\u0435, \u0435\u0441\u043b\u0438 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u0435\u0440\u0438\u0442\u044c \u0432 \u043c\u0430\u0433\u0438\u044e. \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u0442\u043d\u0438\u043c\u0435\u0442 \u0443 \u0432\u0430\u0441 \u0438 \u044d\u0442\u0443 \u0442\u043e\u043b\u0438\u043a\u0443 \u0434\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u0441\u0447\u0430\u0441\u0442\u044c\u044f.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<hr>\n<p>  <font color=\"#387438\"><\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Mockito?<\/h2>\n<p><\/font><br \/>  <a href=\"https:\/\/github.com\/mockito\/mockito\">Mockito<\/a> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0441 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0435\u0439 <a href=\"https:\/\/github.com\/mockito\/mockito\/blob\/release\/3.x\/LICENSE\">MIT License<\/a>.<\/p>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 API \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Mockito \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443\u00bb \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 API. \u0415\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0432 \u043b\u043e\u0433\u0438\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430 \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Spring Boot \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u0427\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043e\u0442\u043e\u0439\u0434\u0451\u043c \u043e\u0442 \u0442\u0435\u043c\u044b \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0435\u0431\u0435 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u043c\u0430\u0445\u043e\u043c \u043f\u0430\u043b\u043e\u0447\u043a\u0438 \u043f\u043e \u0432\u043e\u0437\u0434\u0443\u0445\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u043b \u044f\u0431\u043b\u043e\u043a\u043e \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439. \u0421\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u0435\u0441\u044c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d. \u0410\u0434\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u0438 \u0441\u0430\u043c \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0440\u0430\u0439\u0441\u043a\u043e\u0435 \u044f\u0431\u043b\u043e\u043a\u043e \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043a\u0430\u043a \u044f\u0431\u043b\u043e\u043a\u043e \u043f\u0440\u043e\u043b\u0435\u0442\u0435\u043b\u043e \u043f\u043e \u0432\u043e\u0437\u0434\u0443\u0445\u0443 \u2013 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043c\u0430\u0433\u0438\u0435\u0439.<\/p>\n<p>  \u0422\u0430\u043a \u0438 \u0437\u0434\u0435\u0441\u044c. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d, \u043d\u043e \u043a\u0430\u043a \u0436\u0435 \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d?<\/p>\n<p>  \u041f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0438\u043c\u0441\u044f \u043a \u043a\u043e\u0434\u0443 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0438 \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code class=\"java\">when(apple.getName()).thenReturn(&quot;Red&quot;);<\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 when \u043f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 getName(), \u0430 \u043f\u043e\u0442\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u043c thenReturn. \u041d\u043e \u043a\u0430\u043a \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f? \u041a\u0430\u043a when \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 getName, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442?<\/p>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u0447\u0442\u043e \u043f\u043e\u043b\u0435 name \u043d\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 null.<\/p>\n<p>  \u0417\u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043b\u044e\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0451 \u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0432\u043e\u0432\u0441\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<blockquote><p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/at\/p4\/ig\/atp4igbv9ilmhce6nlnb4-isyoe.png\" align=\"left\" width=\"200\">\u041f\u043e \u043c\u043e\u0435\u043c\u0443 \u043b\u0438\u0447\u043d\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, Mockito \u2013 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041d\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u043a\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u2013 \u0442\u043e\u0436\u0435 \u043d\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u043c\u0435\u0442\u044c \u043e \u043d\u0435\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u2013 \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u0422\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0442\u0440\u0443\u0434\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0441 \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u044f\u0432\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u0412 \u043f\u043e\u043b\u044c\u0437\u0443 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f, \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0438 \u0442\u043e, \u0447\u0442\u043e \u0432 2018 \u0433\u043e\u0434\u0443 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u0430\u043a TestContainers, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0432 Docker \u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0411\u0414\/Kafka\/RabbitMQ.<\/p>\n<p>  \u0415\u0433\u043e\u0440 \u0412\u043e\u0440\u043e\u043d\u044f\u043d\u0441\u043a\u0438\u0439, Java Middle Developer \u0432 BPC Banking Technologies. <br \/>  \u041c\u0435\u043d\u0442\u043e\u0440 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 backend \u043d\u0430 \u043a\u0443\u0440\u0441\u0435 SkillFactory <a href=\"https:\/\/skillfactory.ru\/java?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_JAVA&amp;utm_term=regular&amp;utm_content=120221\">Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430<\/a>  <\/p><\/blockquote>\n<p>  <font color=\"#387438\"><\/p>\n<h2>\u0423\u0447\u0438\u043c\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u043e\u043a\u0443\u0441\u044b<\/h2>\n<p><\/font><br \/>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u043d\u0430\u0448\u0435\u043c \u043c\u0438\u0440\u0435 \u0432\u0441\u044f\u043a\u0430\u044f \u043c\u0430\u0433\u0438\u044f \u2013 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0444\u043e\u043a\u0443\u0441, \u043e\u0431\u043c\u0430\u043d \u0437\u0440\u0435\u043d\u0438\u044f. \u0418 \u043d\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439 \u2013 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u043e\u0442\u0440\u0435\u043f\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435, \u043d\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0434\u043b\u044f \u043b\u044e\u0434\u0435\u0439 \u0441 \u043e\u0441\u0442\u0440\u044b\u043c\u0438 \u0433\u043b\u0430\u0437\u0430\u043c\u0438. \u041d\u043e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0444\u043e\u043a\u0443\u0441, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0433\u0430\u0434\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  \u0420\u0435\u0434\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0444\u043e\u043a\u0443\u0441 \u0443\u0434\u0430\u0451\u0442\u0441\u044f \u0431\u0435\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438. \u0422\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u043e\u043a\u0443\u0441\u043d\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u0443\u044e \u043b\u0435\u0441\u043a\u0443 \u043a \u044f\u0431\u043b\u043e\u043a\u0443.<\/p>\n<p>  \u041d\u0430\u0448\u0438\u043c \u0436\u0435 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 mock:<\/p>\n<pre><code class=\"java\">Apple apple = mock(Apple.class);<\/code><\/pre>\n<p>  \u041e\u0442\u0441\u044e\u0434\u0430 \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 apple \u2013 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u044f\u0431\u043b\u043e\u043a\u043e.<\/p>\n<p>  \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043c\u0435\u0442\u043e\u0434 when, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0435\u043c \u043e\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"java\">@Test public void basic2() {    Apple apple = mock(Apple.class);    System.out.println(apple.getClass().getCanonicalName());    \/\/ org.own.ArticleExample1$Apple$MockitoMock$692964397    System.out.println(apple.getClass().getSuperclass().getCanonicalName());    \/\/ org.own.ArticleExample1.Apple     assertNotEquals(apple.getClass(), Apple.class); \/\/ true  }<\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0441 \u043a\u0435\u043c \u0436\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e? \u041a\u0442\u043e \u0436\u0435 \u044d\u0442\u043e\u0442 \u0441\u0430\u043c\u043e\u0437\u0432\u0430\u043d\u0435\u0446, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0451\u0442 \u0441\u0435\u0431\u044f \u0437\u0430 \u043d\u0430\u0448\u0435 \u044f\u0431\u043b\u043e\u043a\u043e?<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u043c\u0438 \u0434\u0435\u043b\u0430\u043c\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d Proxy. \u0421\u0443\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0441\u0443\u043d\u0443\u0442\u044c \u043d\u0430\u043c \u043d\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043d\u0430\u0448 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 Apple), \u0430 \u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Mockito, \u0442\u043e \u043e\u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0442\u0435\u043c \u0436\u0435, \u043d\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u043d\u0430 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0430. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c <a href=\"https:\/\/github.com\/powermock\/powermock\">PowerMock<\/a> \u0441 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0435\u0439 <a href=\"https:\/\/github.com\/powermock\/powermock\/blob\/release\/2.x\/LICENSE.txt\">Apache-2.0 License<\/a>.<\/p>\n<p>  \u041d\u0443, \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0439 \u0441 Java API, \u0438 \u0442\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u043e\u043c, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430. \u041d\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 PowerMock \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e, \u0445\u043e\u0442\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0432 \u0447\u0451\u043c \u0436\u0435 \u043c\u0438\u043d\u0443\u0441\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>  <font color=\"#387438\"><\/p>\n<h3>Proxy<\/h3>\n<p><\/font><br \/>  \u041d\u0430 \u043f\u0440\u043e\u043a\u0441\u0438, \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u043d\u0430 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0442\u0438\u043f\u0430, \u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u2013 \u043a\u0430\u043a \u043d\u0430 \u0441\u043c\u043e\u0442\u0440\u044f\u0449\u0438\u0439 \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0437\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>  \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f\u0443 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0432\u044b\u0437\u043e\u0432\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u0432\u043e\u0432\u0441\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>  \u0418\u043d\u0434\u0435\u0439\u0441\u043a\u0430\u044f \u043f\u043e\u0441\u043b\u043e\u0432\u0438\u0446\u0430 \u0433\u043b\u0430\u0441\u0438\u0442:\u00a0<\/p>\n<blockquote><p>\u0421\u043a\u0430\u0436\u0438 \u043c\u043d\u0435 \u2013 \u0438 \u044f \u0437\u0430\u0431\u0443\u0434\u0443, \u043f\u043e\u043a\u0430\u0436\u0438 \u043c\u043d\u0435 \u2013 \u0438 \u044f \u043d\u0435 \u0441\u043c\u043e\u0433\u0443 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0438 \u043c\u0435\u043d\u044f \u043a \u0443\u0447\u0430\u0441\u0442\u0438\u044e \u2013 \u0438 \u044f \u043f\u043e\u0439\u043c\u0443.<\/p><\/blockquote>\n<p>  \u0422\u0430\u043a \u0432\u043e\u0442, \u043b\u0435\u0433\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<p>  <a href=\"http:\/\/jdoodle.com\/ia\/7Lm\">ProxyExample<\/a><\/p>\n<pre><code class=\"java\">import java.lang.reflect.Proxy;  \/**  * @author Arthur Kupriyanov  *\/ public class ProxyExample { \tinterface IApple { \t\tString getColor(); \t} \tprivate static class Apple implements IApple { \t\tprivate String color = &quot;red&quot;; \t\tpublic String getColor() { \t\t\treturn color; \t\t} \t}  \tpublic static void main(String[] args) { \t\tObject proxyInstance = Proxy.newProxyInstance( \t\t\t\tProxyExample.class.getClassLoader(), \t\t\t\tApple.class.getInterfaces(), (proxy, method, args1) -&gt; { \t\t\t\t\tSystem.out.println(&quot;Called getColor() method on Apple&quot;); \t\t\t\t\treturn method.invoke(new Apple(), args1); \t\t\t\t});  \t\tIApple appleProxy = (IApple) proxyInstance; \t\tSystem.out.println(appleProxy.getColor()); \t} }<\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u044b\u0432\u043e\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"java\">Called getColor() method on Apple red <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0430 method.invoke \u0441\u0434\u0435\u043b\u0430\u0442\u044c return \u00abGreen\u00bb.<\/p>\n<p>  \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0444\u043e\u043a\u0443\u0441, \u043f\u0440\u0430\u0432\u0434\u0430? \u0422\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u044b \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0446\u0432\u0435\u0442 \u044f\u0431\u043b\u043e\u043a\u0430, \u0430 \u043b\u0438\u0448\u044c \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u0435\u0433\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u044f\u0431\u043b\u043e\u043a\u043e \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u043d\u0430\u043c \u0446\u0432\u0435\u0442\u043e\u043c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0437-\u0437\u0430 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b Proxy \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u0435\u0433\u043e \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u044b:<\/p>\n<ul>\n<li>\u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u00ab\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u00bb \u0432\u044b\u0437\u043e\u0432\u044b \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445, \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u0438 \u043d\u0435\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0445 (final) \u043c\u0435\u0442\u043e\u0434\u043e\u0432.  <\/li>\n<li>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438 \u0438\u0437 \u043d\u0435\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 (final).  <\/li>\n<\/ul>\n<p>  <font color=\"#387438\"><\/p>\n<h2>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u043e\u043a\u0443\u0441<\/h2>\n<p><\/font><br \/>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0438\u043c\u0435\u044f \u043b\u0438\u0448\u044c \u044d\u0442\u043e\u0442 \u0430\u0440\u0441\u0435\u043d\u0430\u043b, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 Mockito.<\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0430\u0448 \u0444\u043e\u043a\u0443\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0443\u0432\u0438\u0434\u0435\u043d\u043d\u044b\u043c \u0440\u0430\u043d\u0435\u0435, \u043d\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0444\u043e\u043a\u0443\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0442\u0435\u043c \u0436\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043d\u0430\u0448\u0438\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c:<\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u043a\u0441\u0438 \u0442\u0438\u043f\u0430 \u0441 \u043d\u0430\u0448\u0438\u043c InvocationHandler \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043d\u0430\u043c \u043b\u043e\u0433\u0438\u043a\u043e\u0439.  <\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434 when, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 thenReturn \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430, \u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c.  <\/li>\n<li>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u0430 2. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0442\u043e \u0432\u0435\u0440\u043d\u0451\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0432\u0435\u0440\u043d\u0435\u043c null.  <\/li>\n<\/ol>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/AppLoidx\/ProxyBasedMockExample\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u0438\u043b\u0438 \u0436\u0435 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0432 <a href=\"http:\/\/tpcg.io\/RZhceBTP\">\u043e\u043d\u043b\u0430\u0439\u043d-\u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435<\/a>.<\/p>\n<pre><code class=\"java\">private static MockInvocationHandler lastMockInvocationHandler;  @SuppressWarnings(&quot;unchecked&quot;) public static &lt;T&gt; T mock(Class&lt;T&gt; clazz) {    MockInvocationHandler invocationHandler = new MockInvocationHandler();    T proxy = (T) Proxy.newProxyInstance(Bourbon.class.getClassLoader(), new Class[]{clazz}, invocationHandler);    return proxy; }  public static &lt;T&gt; When&lt;T&gt; when(T obj) {    return new When&lt;&gt;(); }  public static class When&lt;T&gt; {    public void thenReturn(T retObj) { \t   lastMockInvocationHandler.setRetObj(retObj);    } }  private static class MockInvocationHandler implements InvocationHandler {     private Method lastMethod;    private Object[] lastArgs;    private final List&lt;StoredData&gt; storedData = new ArrayList&lt;&gt;();     private Optional&lt;Object&gt; searchInStoredData(Method method, Object[] args) { \t   for (StoredData storedData : this.storedData) { \t\t   if (storedData.getMethod().equals(method) &amp;&amp; Arrays.deepEquals(storedData.getArgs(), args)) { \t\t\t   \/\/ \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0441\u0442\u044c, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \t\t\t   return Optional.ofNullable(storedData.getRetObj()); \t\t   } \t   }  \t   return Optional.empty();    }     @Override    public Object invoke(Object proxy, Method method, Object[] args) { \t   lastMockInvocationHandler = this; \t   lastMethod = method; \t   lastArgs = args;  \t   \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \t   return searchInStoredData(method, args).orElse(null);     }     public void setRetObj(Object retObj) { \t   storedData.add(new StoredData(lastMethod, lastArgs, retObj));    }     private static class StoredData { \t   private final Object[] args; \t   private final Method method; \t   private final Object retObj;  \t   private StoredData(Method method, Object[] args, Object retObj) { \t\t   this.args = args; \t\t   this.method = method; \t\t   this.retObj = retObj; \t   }  \t   private Object[] getArgs() { \t\t   return args; \t   }  \t   private Method getMethod() { \t\t   return method; \t   }  \t   private Object getRetObj() { \t\t   return retObj; \t   }    }  }<\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u043d\u043e \u043e\u043d \u0432\u043f\u043e\u043b\u043d\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u0435\u043d.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f MockInvocationHandler, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u044e \u043d\u0430\u0448\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u0441 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.\u00a0 \u0412\u0441\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 StoredData, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0431\u044b\u043b\u043e \u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<blockquote><p>\u0422\u0435 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0442\u0435\u043e\u0440\u0438\u044f, \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442 \u0442\u0435\u0431\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430. \u041b\u044e\u0434\u0432\u0438\u0433 \u0424\u0430\u0439\u0435\u0440\u0431\u0430\u0445<\/p><\/blockquote>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043c\u0435\u043b\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c IDE, \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0434 (\u0434\u0443\u043c\u0430\u044e, \u0432 \u044d\u0442\u043e\u043c \u043c\u044b \u0432\u0441\u0435 \u043f\u0440\u043e\u0444\u0438), \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u0435\u043c\u0441\u044f \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043a\u043e\u0434\u0430. \u0411\u043e\u043b\u0435\u0435 \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043e\u043d\u043b\u0430\u0439\u043d-\u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 (\u0441\u0441\u044b\u043b\u043a\u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0430 \u043d\u0430\u0432\u0435\u0440\u0445\u0443 \u043f\u0435\u0440\u0435\u0434 \u043a\u043e\u0434\u043e\u043c) \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0442\u0430\u043c.<\/p>\n<p>  <font color=\"#387438\"><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><\/font><br \/>  Mockito \u0438\u043c\u0435\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e when-thenReturn, \u043d\u043e \u0438 \u0435\u0449\u0451 \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0438 \u043d\u0435 \u0443\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0445 \u043f\u043e \u043a\u0440\u0430\u0441\u043e\u0442\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 Mockito \u0441\u043c\u043e\u0433\u043b\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u0435\u0441\u044c\u043c\u0430 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0438, \u043d\u043e \u0438 \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0434\u0430\u0447\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c. \u0421\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0442\u0430 \u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u043a\u0430\u043a \u0435\u0434\u0438\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u043c \u0444\u043e\u043a\u0443\u0441\u0430. \u042d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u0447\u0442\u043e \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043c\u0430\u0433\u0438\u0435\u0439, \u0445\u043e\u0442\u044f \u0437\u0430 \u043a\u0430\u0434\u0440\u043e\u043c \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0442\u044f\u0436\u0451\u043b\u0430\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 (\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Proxy) \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u043f\u043e\u0438\u0441\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439). <\/p>\n<p>  \u0414\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435: \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441\u0430\u043c\u043e\u0433\u043e Mockito, (\u0445\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0435\u0441\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/mockito\/mockito\">GitHub<\/a>) \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 Spring Boot \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0410 \u044f \u043f\u043e\u0436\u0435\u043b\u0430\u044e \u0432\u0430\u043c \u0443\u0434\u0430\u0447\u0438 \u0432 \u044d\u0442\u043e\u043c \u043f\u0443\u0442\u0438!<\/p>\n<hr>\n<p>  <a href=\"https:\/\/skillfactory.ru\/courses\/?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_ALLCOURSES&amp;utm_term=regular&amp;utm_content=120221\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d83\/613\/0f5\/d836130f52681146c8a1b86a0eaa3a18.png\" alt=\"image\"><\/div>\n<p><\/a><\/p>\n<ul>\n<li><a href=\"https:\/\/skillfactory.ru\/java?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_JAVA&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/java-qa-engineer?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_QAJA&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f QA-\u0438\u043d\u0436\u0435\u043d\u0435\u0440 \u043d\u0430 JAVA<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/dstpro?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_DSPR&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Data Scientist<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/dataanalystpro?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_DAPR&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Data Analyst<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u0438 \u0438 \u043a\u0443\u0440\u0441\u044b<\/b>                         <\/p>\n<div class=\"spoiler_text\"><strong>\u041f\u0420\u041e\u0424\u0415\u0421\u0421\u0418\u0418<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/skillfactory.ru\/java?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_JAVA&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/frontend?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_FR&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Frontend-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/cybersecurity?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_HACKER&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f \u042d\u0442\u0438\u0447\u043d\u044b\u0439 \u0445\u0430\u043a\u0435\u0440<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/cplus?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_CPLUS&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f C++ \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/game-dev?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_GAMEDEV&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0433\u0440 \u043d\u0430 Unity<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/webdev?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_WEBDEV&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f \u0412\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/iosdev?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_IOSDEV&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u043d\u0443\u043b\u044f<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/android?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_ANDR&amp;utm_term=regular&amp;utm_content=120221\">\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u043d\u0443\u043b\u044f<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<hr>\n<p>  <strong>\u041a\u0423\u0420\u0421\u042b<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/skillfactory.ru\/ml-programma-machine-learning-online?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_ML&amp;utm_term=regular&amp;utm_content=120221\">\u041a\u0443\u0440\u0441 \u043f\u043e Machine Learning<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/math_and_ml?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_MATML&amp;utm_term=regular&amp;utm_content=120221\">\u041a\u0443\u0440\u0441 \u00ab\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0438 Machine Learning \u0434\u043b\u044f Data Science\u00bb<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/dataengineer?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_DEA&amp;utm_term=regular&amp;utm_content=130121\">\u041a\u0443\u0440\u0441 \u043f\u043e Data Engineering<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/python-for-web-developers?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_PWS&amp;utm_term=regular&amp;utm_content=120221\">\u041a\u0443\u0440\u0441 \u00abPython \u0434\u043b\u044f \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438\u00bb<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/algo?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_algo&amp;utm_term=regular&amp;utm_content=120221\">\u041a\u0443\u0440\u0441 \u00ab\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445\u00bb<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/analytics?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_SDA&amp;utm_term=regular&amp;utm_content=120221\">\u041a\u0443\u0440\u0441 \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/li>\n<li><a href=\"https:\/\/skillfactory.ru\/devops?utm_source=infopartners&amp;utm_medium=habr&amp;utm_campaign=habr_DEVOPS&amp;utm_term=regular&amp;utm_content=120221\">\u041a\u0443\u0440\u0441 \u043f\u043e DevOps<\/a><\/li>\n<\/ul>\n<p>  <\/div>\n<\/p><\/div>\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\/company\/skillfactory\/blog\/541364\/\"> https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/541364\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><a href=\"https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/541762\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/da\/xr\/k6\/daxrk6esxcf6kbmnjgvxu_ytcxe.jpeg\"><\/div>\n<p><\/a><br \/>  \u0414\u0443\u043c\u0430\u044e, \u043c\u043d\u043e\u0433\u0438\u043c \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u0432\u044b\u043f\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0430\u043f\u0438\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u043f\u0438\u043b\u0441\u044f \u0432 \u043d\u0430\u0448\u0438 \u0432\u043a\u0443\u0441\u043e\u0432\u044b\u0435 \u0440\u0435\u0446\u0435\u043f\u0442\u043e\u0440\u044b, \u0447\u0442\u043e \u043d\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c. \u0422\u0430\u043a \u0432\u043e\u0442 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0442\u0430\u043a\u0438\u043c \u00ab\u043d\u0430\u043f\u0438\u0442\u043a\u043e\u043c\u00bb \u0441\u0442\u0430\u043b Mockito. \u041e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0442\u0435\u0441\u0442, \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0435\u0431\u0435 \u0432\u0435\u0440\u0443 \u0432 \u043c\u0430\u0433\u0438\u044e. \u042f \u0432\u0441\u0451 \u0435\u0449\u0451 \u043f\u043e\u043c\u043d\u044e, \u043a\u0430\u043a \u0443\u0434\u0438\u0432\u043b\u044f\u043b\u0441\u044f \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. <\/p>\n<p>  \u0427\u0435\u043c\u0443 \u0436\u0435 \u044f \u0443\u0434\u0438\u0432\u0438\u043b\u0441\u044f? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e\u043c\u0443:<\/p>\n<pre><code class=\"java\">private static class Apple {    private String color;    public String getName() {return color;} }  @Test public void basic() {    Apple apple = mock(Apple.class);    when(apple.getName()).thenReturn(&quot;Red&quot;);    assertEquals(&quot;Red&quot;, apple.getName()); \/\/ true }<\/code><\/pre>\n<p>  \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e:<\/p>\n<ul>\n<li>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440-\u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Apple.  <\/li>\n<li>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043a\u0430\u043a \u0431\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 apple.getColor(), \u0442\u043e \u0432\u0435\u0440\u043d\u0438 \u00abRed\u00bb.  <\/li>\n<li>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 apple.getColor() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!  <\/li>\n<\/ul>\n<p>  \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041d\u0435 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u0430\u043b\u044c\u0448\u0435, \u0435\u0441\u043b\u0438 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u0435\u0440\u0438\u0442\u044c \u0432 \u043c\u0430\u0433\u0438\u044e. \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u0442\u043d\u0438\u043c\u0435\u0442 \u0443 \u0432\u0430\u0441 \u0438 \u044d\u0442\u0443 \u0442\u043e\u043b\u0438\u043a\u0443 \u0434\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u0441\u0447\u0430\u0441\u0442\u044c\u044f.<\/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-317918","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/317918","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=317918"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/317918\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}