{"id":20797,"date":"2014-01-24T10:00:17","date_gmt":"2014-01-24T08:00:17","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=20797"},"modified":"2014-01-24T09:49:54","modified_gmt":"2014-01-24T07:49:54","slug":"testing-spring-components-with-mockito","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html","title":{"rendered":"Testing Spring components with Mockito"},"content":{"rendered":"<p>Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion, a great advantage because it&#8217;s clean, easy to maintain, faster to write, smooth to alter.<\/p>\n<p>A way to achieve this goal is to use <a href=\"http:\/\/docs.mockito.googlecode.com\/hg\/latest\/org\/mockito\/Mockito.html\" target=\"_blank\">Mockito<\/a> and tell him to replace the @Autowired components in the class you want to test, with Mocks ( or Spies ).<\/p>\n<p>Here an example.<\/p>\n<p>We have a service called SalaryService that guess what, is calculating a hypothetical net salary based on the employee id passed. Easy concept.<\/p>\n<p>The service required to collaborators, one, the EmployeeDAO, to retrieve the gross salary and a second one, the TaxCalculator, to apply some taxes based on the gross salary.<\/p>\n<pre class=\" brush:java\">package com.marco.springmockito;\r\nimport java.math.BigDecimal;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class SalaryService {\r\n\r\n\u00a0 \u00a0 private static final BigDecimal minimumSalary = new BigDecimal(20000);\r\n\r\n\u00a0 \u00a0 @Autowired\r\n\u00a0 \u00a0 private EmployeeDAO employeeDAO;\r\n\r\n\u00a0 \u00a0 @Autowired\r\n\u00a0 \u00a0 private TaxCalculator taxCalculator;\r\n\r\n\u00a0 \u00a0 public BigDecimal getNetSalary(long employeeId) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal netSalary = null;\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal grossSalary = employeeDAO.getAnnualSalary(employeeId);\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal taxes = taxCalculator.calculateTaxes(grossSalary);\r\n\u00a0 \u00a0 \u00a0 \u00a0 if (taxedSalaryIsGreaterThanMinimumSalary(grossSalary)) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 netSalary = grossSalary.subtract(taxes);\r\n\u00a0 \u00a0 \u00a0 \u00a0 } else {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 netSalary = grossSalary;\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 return netSalary;\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 private boolean taxedSalaryIsGreaterThanMinimumSalary(BigDecimal taxedSalary) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 return taxedSalary.compareTo(minimumSalary) == 1;\r\n\u00a0 \u00a0 }\r\n}<\/pre>\n<p>EmployeeDAO is a classical service that is in charge of retrieving information from a persistence storage and it will look like this more or less.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:java\">package com.marco.springmockito;\r\nimport java.math.BigDecimal;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class EmployeeDAO {\r\n\r\n\u00a0 \u00a0 public BigDecimal getAnnualSalary(long employeeId) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ conncetTODB\r\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ run select for employeeId;\r\n\u00a0 \u00a0 \u00a0 \u00a0 return new BigDecimal(70000);\r\n\u00a0 \u00a0 }\r\n}<\/pre>\n<p>TaxCalculator will need a TaxDao to retrieve taxes information and it will then operate some sort of boring and long calculation in order to return the taxes.<\/p>\n<pre class=\" brush:java\">package com.marco.springmockito;\r\nimport java.math.BigDecimal;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Component;\r\n@Component\r\npublic class TaxCalculator {\r\n\r\n\u00a0 \u00a0 @Autowired\r\n\u00a0 \u00a0 private TaxDao taxDao;\r\n\r\n\u00a0 \u00a0 public BigDecimal calculateTaxes(BigDecimal salary) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal result = salary.multiply(taxDao.getTaxPercentageForYear(2014));\r\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ some other weird calculation ....\r\n\u00a0 \u00a0 \u00a0 \u00a0 return result;\r\n\u00a0 \u00a0 }\r\n}<\/pre>\n<p>Now, we want to unit test the SalaryService class. We should not to be bothered by DAOs and databases setup of any sort. In this UNIT test, we don&#8217;t care here what the TaxCalculator is doing.<\/p>\n<p>What we want is to test that our SalaryService is behaving as expected and that it is able to correctly use the work of its collaborators.<\/p>\n<p>Here is how we do it with Mockito. We mark the class we want to test with <a href=\"http:\/\/docs.mockito.googlecode.com\/hg\/latest\/org\/mockito\/InjectMocks.html\" target=\"_blank\">@InjectMocks<\/a> and we mark with <a href=\"http:\/\/docs.mockito.googlecode.com\/hg\/latest\/org\/mockito\/Mock.html\" target=\"_blank\">@Mock<\/a> all of its collaborators ( or <a href=\"http:\/\/docs.mockito.googlecode.com\/hg\/latest\/org\/mockito\/Spy.html\" target=\"_blank\">@Spy<\/a> if you need a real implementation ).<\/p>\n<p>Lastly we need to tell our Unit framework, to operate the required Mockito injections before starting the test and we do this with<br \/>\nMockitoAnnotations. initMocks (this);.<\/p>\n<p>In the test we need to mock the expected operations so that we can concentrate on the actual logic we want to test inside the SalaryService .<\/p>\n<pre class=\" brush:java\">package com.marco.springmockito;\r\nimport static org.hamcrest.core.Is.is;\r\nimport static org.junit.Assert.assertThat;\r\nimport static org.mockito.Mockito.when;\r\nimport java.math.BigDecimal;\r\nimport org.junit.Before;\r\nimport org.junit.Test;\r\nimport org.mockito.InjectMocks;\r\nimport org.mockito.Mock;\r\nimport org.mockito.MockitoAnnotations;\r\npublic class SalaryServiceTest {\r\n\r\n\u00a0 \u00a0 private static final long UserId = 123l;\r\n\r\n\u00a0 \u00a0 @InjectMocks\r\n\u00a0 \u00a0 private SalaryService salaryService;\r\n\r\n\u00a0 \u00a0 @Mock\r\n\u00a0 \u00a0 private EmployeeDAO employeeDAO;\r\n\r\n\u00a0 \u00a0 @Mock\r\n\u00a0 \u00a0 private TaxCalculator taxCalculator;\r\n\r\n\u00a0 \u00a0 @Before\r\n\u00a0 \u00a0 public void init() {\r\n\u00a0 \u00a0 \u00a0 \u00a0 MockitoAnnotations.initMocks(this);\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 @Test\r\n\u00a0 \u00a0 public void testMinimumSalary() {\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal annualSalary = new BigDecimal(10000);\r\n\u00a0 \u00a0 \u00a0 \u00a0 when(employeeDAO.getAnnualSalary(UserId)).thenReturn(annualSalary);\r\n\u00a0 \u00a0 \u00a0 \u00a0 when(taxCalculator.calculateTaxes(annualSalary)).thenReturn(new BigDecimal(1000));\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal actual = salaryService.getNetSalary(UserId);\r\n\u00a0 \u00a0 \u00a0 \u00a0 assertThat(actual.compareTo(new BigDecimal(10000)), is(0));\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 @Test\r\n\u00a0 \u00a0 public void testMaximumSalary() {\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal annualSalary = new BigDecimal(80000);\r\n\u00a0 \u00a0 \u00a0 \u00a0 when(employeeDAO.getAnnualSalary(UserId)).thenReturn(annualSalary);\r\n\u00a0 \u00a0 \u00a0 \u00a0 when(taxCalculator.calculateTaxes(annualSalary)).thenReturn(new BigDecimal(8000));\r\n\u00a0 \u00a0 \u00a0 \u00a0 BigDecimal actual = salaryService.getNetSalary(UserId);\r\n\u00a0 \u00a0 \u00a0 \u00a0 assertThat(actual.compareTo(new BigDecimal(72000)), is(0));\r\n\u00a0 \u00a0 }\r\n}<\/pre>\n<p>It is simple and efficient and hopefully it will be useful for someone else out there.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/rdafbn.blogspot.com\/2014\/01\/testing-spring-components-with-mockito.html\">Testing Spring components with Mockito<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Marco Castigliego at the <a href=\"http:\/\/rdafbn.blogspot.com\/\">Remove duplication and fix bad names<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion, a great advantage because it&#8217;s clean, easy to maintain, faster to write, smooth to alter. A way to achieve this goal is to use Mockito and tell him to &hellip;<\/p>\n","protected":false},"author":284,"featured_media":186,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[460,30,273],"class_list":["post-20797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-mockito","tag-spring","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Testing Spring components with Mockito<\/title>\n<meta name=\"description\" content=\"Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Testing Spring components with Mockito\" \/>\n<meta property=\"og:description\" content=\"Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-24T08:00:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Marco Castigliego\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marco Castigliego\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html\"},\"author\":{\"name\":\"Marco Castigliego\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/bfec195771720f1ac481053f82234d03\"},\"headline\":\"Testing Spring components with Mockito\",\"datePublished\":\"2014-01-24T08:00:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html\"},\"wordCount\":370,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"keywords\":[\"Mockito\",\"Spring\",\"Testing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html\",\"name\":\"Testing Spring components with Mockito\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"datePublished\":\"2014-01-24T08:00:17+00:00\",\"description\":\"Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion,\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/testing-spring-components-with-mockito.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Testing Spring components with Mockito\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/bfec195771720f1ac481053f82234d03\",\"name\":\"Marco Castigliego\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g\",\"caption\":\"Marco Castigliego\"},\"sameAs\":[\"http:\\\/\\\/rdafbn.blogspot.ie\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Marco-Castigliego\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Testing Spring components with Mockito","description":"Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html","og_locale":"en_US","og_type":"article","og_title":"Testing Spring components with Mockito","og_description":"Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion,","og_url":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-01-24T08:00:17+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","type":"image\/jpeg"}],"author":"Marco Castigliego","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Marco Castigliego","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html"},"author":{"name":"Marco Castigliego","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/bfec195771720f1ac481053f82234d03"},"headline":"Testing Spring components with Mockito","datePublished":"2014-01-24T08:00:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html"},"wordCount":370,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","keywords":["Mockito","Spring","Testing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html","url":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html","name":"Testing Spring components with Mockito","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","datePublished":"2014-01-24T08:00:17+00:00","description":"Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion,","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/testing-spring-components-with-mockito.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Testing Spring components with Mockito"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/bfec195771720f1ac481053f82234d03","name":"Marco Castigliego","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a3ce5aa7be5badd7ad76ed9d915522609d05ebe32c50fa96595c58f3bc3bdcab?s=96&d=mm&r=g","caption":"Marco Castigliego"},"sameAs":["http:\/\/rdafbn.blogspot.ie\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Marco-Castigliego"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/20797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/284"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=20797"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/20797\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/186"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=20797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=20797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=20797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}