{"id":4435,"date":"2021-07-04T14:05:28","date_gmt":"2021-07-04T14:05:28","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=4435"},"modified":"2021-07-04T15:52:58","modified_gmt":"2021-07-04T15:52:58","slug":"using-testtraits-in-mockito","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/using-testtraits-in-mockito\/","title":{"rendered":"Using TestTraits in Mockito"},"content":{"rendered":"<p><strong>TestTraits.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic interface TestTraits {\r\n    String EMPLOYEE_ID = &quot;1&quot;;\r\n    Long EMPLOYEE_ID_LONG = 1L;\r\n\r\n    default EmployeeRpy getEmployee(){\r\n        EmployeeRpy objEmpRpy = new EmployeeRpy();\r\n        objEmpRpy.setEmpName(&quot;Mugil&quot;);\r\n        objEmpRpy.setEmpAge(&quot;34&quot;);\r\n        return objEmpRpy;\r\n\r\n     default EmployeeDetailsResource createMockedEmployeeDetails() \r\n          throws IOException(){\r\n       EmployeeDetailsResource objEmployeeDetailsResource = \r\n              new Gson.fromJson(getReader(&quot;json-data\/EmployeeDetails.json&quot;), EmployeeDetails.class);    \r\n       return objEmployeeDetailsResource; \r\n     } \r\n\r\n     default Reader getReader(String filePath) throws IOException{\r\n       return new FileReader(new ClassPathResource(filePath).getFile());  \r\n     }\r\n}\r\n<\/pre>\n<p><strong>EmployeeDetails.json<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n  {\r\n     &quot;empID&quot; : &quot;101&quot;,\r\n     &quot;empName&quot; : &quot;Mugilvannan&quot;,\r\n     &quot;empAge&quot; : &quot;30&quot;\r\n  } \r\n<\/pre>\n<p><strong>EmployeeMgmtTest.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n @ExtendWith({MockitoExtension.class})\r\n class EmployeeMgmtTest implements TestTraits{\r\n    .\r\n    . \r\n    Code for Testing Goes Here\r\n    .\r\n    .\r\n }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>TestTraits.java public interface TestTraits { String EMPLOYEE_ID = &quot;1&quot;; Long EMPLOYEE_ID_LONG = 1L; default EmployeeRpy getEmployee(){ EmployeeRpy objEmpRpy = new EmployeeRpy(); objEmpRpy.setEmpName(&quot;Mugil&quot;); objEmpRpy.setEmpAge(&quot;34&quot;); return objEmpRpy; default EmployeeDetailsResource createMockedEmployeeDetails() throws IOException(){ EmployeeDetailsResource objEmployeeDetailsResource = new Gson.fromJson(getReader(&quot;json-data\/EmployeeDetails.json&quot;), EmployeeDetails.class); return objEmployeeDetailsResource; } default Reader getReader(String filePath) throws IOException{ return new FileReader(new ClassPathResource(filePath).getFile()); } } EmployeeDetails.json { &quot;empID&quot; :&hellip; <a href=\"https:\/\/codethataint.com\/blog\/using-testtraits-in-mockito\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[324,331],"tags":[],"class_list":["post-4435","post","type-post","status-publish","format-standard","hentry","category-mockito","category-junit5"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=4435"}],"version-history":[{"count":4,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4435\/revisions"}],"predecessor-version":[{"id":4442,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/4435\/revisions\/4442"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=4435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=4435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=4435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}