<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: koduki</title>
    <description>The latest articles on DEV Community by koduki (@koduki).</description>
    <link>https://dev.to/koduki</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F73599%2F77f2de6d-445a-410a-8306-fb53a2e95ecd.png</url>
      <title>DEV Community: koduki</title>
      <link>https://dev.to/koduki</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/koduki"/>
    <language>en</language>
    <item>
      <title>Zero Trust Network for comfortable WFH</title>
      <dc:creator>koduki</dc:creator>
      <pubDate>Sat, 04 Apr 2020 08:28:10 +0000</pubDate>
      <link>https://dev.to/koduki/zero-trust-network-for-comfortable-wfh-1njf</link>
      <guid>https://dev.to/koduki/zero-trust-network-for-comfortable-wfh-1njf</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Zero Trust Network is post VPN for remote access.&lt;/li&gt;
&lt;li&gt;Base on HTTPS and Context awareness access Control(CAAC)&lt;/li&gt;
&lt;li&gt;Big paradigm shift from Firewall boundary to ID boundary&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Zero Trust Security?
&lt;/h2&gt;

&lt;p&gt;Do you know Zero Trust Security? &lt;/p&gt;

&lt;p&gt;Now many people work from home due to Coronavirus disease (COVID-19).&lt;br&gt;
This is very very bad situation for your life, health and global economy.&lt;br&gt;
However, it is good opportunity to consider about remote access.&lt;/p&gt;

&lt;p&gt;Roughly speaking, we can understand Zero Trust Network is post VPN.&lt;br&gt;
This concept is simple, "Never trust, anywhere and anyone".&lt;/p&gt;

&lt;p&gt;Traditional VPN and Offie network are &lt;strong&gt;base on trust networks&lt;/strong&gt;.&lt;br&gt;
It made trust network in office and DC. These physical facilities are connected trust network like dedicate line. And they are protected Firewall.&lt;br&gt;
Firewall is the Great Wall to separate trust networks and untrusted &lt;br&gt;
 networks. Security solutions take care a lot about access from untrusted  networks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lLBCRvS5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7tgrs75j9536tyaloobq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lLBCRvS5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7tgrs75j9536tyaloobq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image: Traditional office networks&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;VPN is only way to connect trust networks through untrusted networks as the special solution.&lt;/p&gt;

&lt;p&gt;On the other hands, Zero Trust Network is &lt;strong&gt;base on untrusted networks&lt;/strong&gt;.&lt;br&gt;
Today, remote access is very natural requirement. And Attacks have gotten more malus continuously. We have to take care about access from even trust network. That's why zero trust network start from untrusted network. So they can provide same security models whether trust networks or untrusted networks.&lt;br&gt;
This approach protect systems by IDaaS like AzureAD or Google Cloud Identity instead of network firewall.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Brjs47JG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jowq4lxl45exf6u6okzc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Brjs47JG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jowq4lxl45exf6u6okzc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image: Zero Trust networks&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Whether from office or home, each access is controlled by &lt;em&gt;Context&lt;/em&gt; like user account, device, location and target application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need post VPN?
&lt;/h2&gt;

&lt;p&gt;Before deep diving to Zero trust network, let me explain why do we need post VPN.&lt;/p&gt;

&lt;p&gt;There is two issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;li&gt;Difficulty of right access control&lt;/li&gt;
&lt;li&gt;Consistent security policy&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;p&gt;VPN performance is not so good. Because encryption is heavy task and it has latency problem. Even we want to connect to SaaS, we need access data center as VPN access hub. It is an extra connection.&lt;/p&gt;

&lt;p&gt;In addition, capacity plan is difficult. Because in the normal situation, only very few people will access from remote. However disaster situation like now, remote access will increase dramatically for BCP.&lt;br&gt;
Honestly specking, it's difficult to always secure enough capacity for emergency.&lt;/p&gt;

&lt;h3&gt;
  
  
  Difficulty of right access control
&lt;/h3&gt;

&lt;p&gt;VPN looks internal access, so it difficult to control office or home by application side.&lt;br&gt;
For example, if you want only approve e-mail and some reporting tool from remote but you don't want to access business application which includes customer information. This requirement is natural. However if you want to realize, you may need to make or change firewall and network configuration. You need take care about network segment of each application. If you want to change such a remote access privilege level depending on role or person, you also need to take care about IP address which is distributed by VPN. If you want to utilize VDI(Virtual Desktop Infrastructure), issue will be complex more and more.&lt;/p&gt;

&lt;p&gt;This is a big problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Consistent security policy
&lt;/h3&gt;

&lt;p&gt;We should use consistent security model to avoid complexity.&lt;br&gt;
However, tradition office network is difficult to do it.&lt;/p&gt;

&lt;p&gt;First of all, it only provides security through trust network. Because almost security solutions like AV, EDR, CASB, device management are deployed on data center. This mean remote device is only applied through VPN. If VPN is not connected, that device is not secure. The problem is  caused by that only the office is the first citizen and remote access is not.&lt;/p&gt;

&lt;p&gt;Second is SaaS. Office networks changed. We utilize not only intra system but also many SaaS product for our business environment. In this case, we also take care about SaaS access control and generally it is separated from current office configurations.&lt;/p&gt;

&lt;p&gt;From these three reasons, we need to consider about new security model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Context-Aware Access Control (CAAC)
&lt;/h2&gt;

&lt;p&gt;CAAC is key component for zero trust security network.&lt;br&gt;
Role base access control (RBAC) verify user/role and target application. This is a better approach than just Network access control (NAC). Generally, we combinate NAC + RBAC.  But it still not enough.&lt;/p&gt;

&lt;p&gt;CAAC verify user/role, device, location and target application. Location is typically network. So CAAC realize same control with NAC + RBAC by only single security control. &lt;/p&gt;

&lt;p&gt;Below is an example scenario.&lt;/p&gt;

&lt;p&gt;This sales staff can access to their customer management (CRM) system from office.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dJEj0UTs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nhknnlq5i4bn6zxjmpos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dJEj0UTs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nhknnlq5i4bn6zxjmpos.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, even same person and same device can't access to their CRM from office.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AI0shr3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lj9jw2yzdhz3os7vjci2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AI0shr3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lj9jw2yzdhz3os7vjci2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And he can access Office 365 like e-mail and one drive from home. However ind this case, he is required additional authentication like MFA.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dJEj0UTs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nhknnlq5i4bn6zxjmpos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dJEj0UTs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nhknnlq5i4bn6zxjmpos.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CAAC realize such a control easily. If we want do same control by NAC + RBSC, it is very complex configurations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Conditional access&lt;/em&gt; of Azure AD and &lt;em&gt;Cloud IAP&lt;/em&gt; of GCP are popular implementation of CAAC.&lt;/p&gt;

&lt;h2&gt;
  
  
  Office network with Zero Trust Network
&lt;/h2&gt;

&lt;p&gt;Zero Trust Network is ID base security boundary. It is able to apply same control both office and home by CAAC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Brjs47JG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jowq4lxl45exf6u6okzc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Brjs47JG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jowq4lxl45exf6u6okzc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To utilize this control, typical we use cloud security for endpoint security like AV, EDR, CASB, device management.&lt;br&gt;
These tools can apply security whether trust networks or untrusted networks. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--42DWEIDg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uydbf65jqpw2loo0hvzv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--42DWEIDg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uydbf65jqpw2loo0hvzv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Form CAAC and Cloud Security, we can resolve &lt;em&gt;Difficulty of right access control&lt;/em&gt; and &lt;em&gt;Consistent security policy&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In addition, Zero Trust Network doesn't apply extra encryption. Because every application should support HTTPS/TLS. Then they don't need extra overhead by encryption.&lt;/p&gt;

&lt;p&gt;Someone may afraid HTTPS is less secure than VPN, but it's not true.&lt;br&gt;
VPN is based on TLS. So security level is completely same with HTTPS. Sometime VPN also support device trust. But IDaaS like Azure AD also support device trust with Intune. So we can say "It's completely same with VPN".&lt;/p&gt;

&lt;p&gt;Finally, zero trust security network doesn't take care about remote access or NOT. This mean everyone has capability of remote access. It is just control. So even if remote access increase by BCP, capacity is always enough. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;VPN was good solution. However it has some issues today.&lt;br&gt;
We should shift from traditional network model to zero trust networks.&lt;/p&gt;

&lt;p&gt;Of course, migration is not easy. However always improvement is only way to keep security.&lt;/p&gt;

&lt;p&gt;We should be consider everything about security.&lt;/p&gt;

&lt;p&gt;Happy Hacking!&lt;/p&gt;

</description>
      <category>security</category>
    </item>
    <item>
      <title>Technology landscape for Identification Management System</title>
      <dc:creator>koduki</dc:creator>
      <pubDate>Thu, 11 Jul 2019 06:31:01 +0000</pubDate>
      <link>https://dev.to/koduki/technology-landscape-for-identification-management-system-33jl</link>
      <guid>https://dev.to/koduki/technology-landscape-for-identification-management-system-33jl</guid>
      <description>&lt;h2&gt;
  
  
  Preface
&lt;/h2&gt;

&lt;p&gt;Identification Management System is very important component for both enterprise and consumer.&lt;/p&gt;

&lt;p&gt;Especially, &lt;strong&gt;MFA&lt;/strong&gt; is very hot topic. Anyone know about MFA. But do you know MFA &lt;strong&gt;clearly&lt;/strong&gt;? It is &lt;strong&gt;NOT&lt;/strong&gt; MFA to just use SMS or biometrics.&lt;/p&gt;

&lt;p&gt;Let me explain the technology trend for Identification Management System like MFA, Risk-based authentication, CAAC and SSO.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication/Authorization
&lt;/h2&gt;

&lt;p&gt;As you know &lt;strong&gt;Auth&lt;/strong&gt; has two mean — &lt;strong&gt;Authentication&lt;/strong&gt; and &lt;strong&gt;Authorization&lt;/strong&gt;.  These are very similar word. But different is simple.&lt;/p&gt;

&lt;p&gt;Authentication is &lt;strong&gt;Identify&lt;/strong&gt;. This mean "Who are you?".  Authorization is &lt;strong&gt;Access Control&lt;/strong&gt;. This mean "What is permitted for you?"&lt;/p&gt;

&lt;p&gt;For example, &lt;strong&gt;OpenID&lt;/strong&gt; is a technology for Identify and &lt;strong&gt;OAuth&lt;/strong&gt; is a technology for Access Control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Factor Authentication(MFA)
&lt;/h2&gt;

&lt;p&gt;MFA/2FA is very hot technology. But it doesn't mean to use SMS or biometrics. And please be careful about difference with &lt;strong&gt;two-step verification&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-63-3.pdf" rel="noopener noreferrer"&gt;NIST Special Publication 800-63-3 Digital Identity Guidelines&lt;/a&gt;, there is &lt;strong&gt;three factor of authentication&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Something you know&lt;/li&gt;
&lt;li&gt;Something you have&lt;/li&gt;
&lt;li&gt;Something you are&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Something you know"&lt;/em&gt;&lt;/strong&gt; is knowledge which is known only right user. Password or PIN are typically examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Something you have"&lt;/em&gt;&lt;/strong&gt; is property which is had only right user. SMS(Phone Number), mail address, token generator, hardware key/card, IP address and Geo-location are typically examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Something you are"&lt;/em&gt;&lt;/strong&gt; is biometrics. Fingerprint, face and iris are typically examples. Smartphone and AI help this area today.&lt;/p&gt;

&lt;p&gt;MFA is &lt;strong&gt;a combination of over two factor&lt;/strong&gt;. This mean &lt;strong&gt;2nd password is NOT 2FA&lt;/strong&gt;. It's &lt;strong&gt;only two-step verification&lt;/strong&gt; with single factor. Because password and 2nd password are both &lt;strong&gt;&lt;em&gt;"Something you know"&lt;/em&gt;&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;Single factor is &lt;strong&gt;easy to hack by same way&lt;/strong&gt;. So combination is important.&lt;/p&gt;

&lt;p&gt;Especially  almost &lt;strong&gt;attacker already knows about right ID and password&lt;/strong&gt;. Then we need to &lt;strong&gt;additional factor&lt;/strong&gt; for important operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fraud detection
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Monitoring&lt;/strong&gt; and &lt;strong&gt;Fraud detection&lt;/strong&gt; is very important part for Identification Management. Because &lt;strong&gt;attacker already knows about right ID and password&lt;/strong&gt; . But we need defect fraud.&lt;/p&gt;

&lt;p&gt;Internet Protocol Address &lt;strong&gt;(IPA) Location&lt;/strong&gt;, &lt;strong&gt;Geo-Location&lt;/strong&gt;  and &lt;strong&gt;time&lt;/strong&gt; are important information for this.&lt;/p&gt;

&lt;p&gt;Because if someone accessed in USA five minutes after being accessed in Japan, maybe it's &lt;strong&gt;illegal access&lt;/strong&gt;. Such a access &lt;strong&gt;should be rejected&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Risk-based authentication
&lt;/h2&gt;

&lt;p&gt;Risk-based authentication is improvement of fraud detection. Sometime we use new PC and we move to another location.&lt;/p&gt;

&lt;p&gt;If it's only provided fraud detection, we can't log-in in such a situation. It is NOT user-friendly.&lt;/p&gt;

&lt;p&gt;So Risk-based authentication manages such a &lt;strong&gt;irregular access patterns as risk&lt;/strong&gt;. And it requires more &lt;strong&gt;additional authentication&lt;/strong&gt; like SMS, e-Mail and so on. This is very useful function.&lt;/p&gt;

&lt;p&gt;In general, smartphone industry call this behavior as &lt;strong&gt;two-step verification&lt;/strong&gt; with SMS authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Context-aware access Control (CAAC)
&lt;/h2&gt;

&lt;p&gt;Context-aware access control is mainly for enterprise system. It is a extetnion of &lt;a href="https://en.wikipedia.org/wiki/Role-based_access_control" rel="noopener noreferrer"&gt;role-based access control (RBAC)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It &lt;strong&gt;dynamically&lt;/strong&gt; determines access capability according to the following factors.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User&lt;/li&gt;
&lt;li&gt;Device&lt;/li&gt;
&lt;li&gt;Location&lt;/li&gt;
&lt;li&gt;Target system&lt;/li&gt;
&lt;li&gt;Target operation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, we can control access level by office or home. And it is able to &lt;strong&gt;require additional authentication factor&lt;/strong&gt; like hardware-key when user is on their home.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/active-directory/conditional-access/overview" rel="noopener noreferrer"&gt;Azure AD Conditional Access&lt;/a&gt; and &lt;a href="https://cloud.google.com/iap/" rel="noopener noreferrer"&gt;Google Cloud IAP&lt;/a&gt; provide this feature. It's key component for &lt;strong&gt;Zero Trust Security&lt;/strong&gt;. This is only way for security control for SaaS. Because Cloud Age is &lt;strong&gt;every access is Remote Access&lt;/strong&gt; . VPN is NOT enough now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single Sign On (SSO)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;SSO&lt;/strong&gt; is not new technology for Enterprise. LDAP and Acitive Direcotry and each cloud vendor's IAMs provide this function. It's natural way for enterprise systems.&lt;/p&gt;

&lt;p&gt;Maybe someone may think that &lt;strong&gt;SSO is for usability for employee&lt;/strong&gt;. But it's &lt;strong&gt;NOT correct&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSO is for security&lt;/strong&gt;. As you already know, &lt;strong&gt;Identification Management is very complex system&lt;/strong&gt;. It's required a lot of features like MFA, Fraud Detection and monitoring and Context-aware access.&lt;/p&gt;

&lt;p&gt;If we don't use SSO, individual system has own account. And user needs to manage their password. It &lt;strong&gt;looks secure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But &lt;strong&gt;it's difficult to make the best auth features for individual systems&lt;/strong&gt; and it's &lt;strong&gt;not realistic scenario&lt;/strong&gt; to be managed many passwords &lt;strong&gt;properly&lt;/strong&gt; by every user. Maybe &lt;strong&gt;they use same password for every system&lt;/strong&gt; to help their brain memory. It's not secure.&lt;/p&gt;

&lt;p&gt;So we &lt;strong&gt;use SSO&lt;/strong&gt; for security with &lt;strong&gt;trusted ID systems&lt;/strong&gt;. This is &lt;strong&gt;the best practices!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This diagram is summary of Identification Management System.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft861bvmob1i6p5wehraa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft861bvmob1i6p5wehraa.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most importantly, &lt;strong&gt;Identification Management System is very complex&lt;/strong&gt;. We &lt;strong&gt;shouldn't make by ourself&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you make &lt;strong&gt;a system for consumer&lt;/strong&gt;, you should use &lt;strong&gt;Social Service ID&lt;/strong&gt; like Google, GitHub, Twitter and Facebook with &lt;strong&gt;OpenID Connect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And if you make &lt;strong&gt;a system for business&lt;/strong&gt;, you should use &lt;strong&gt;IDaaS&lt;/strong&gt; like AzureAD with &lt;strong&gt;SAML 2.0&lt;/strong&gt; or &lt;strong&gt;OpenID Connect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It's the best practice and only way to avoid Identify Issues, I believe.&lt;/p&gt;

&lt;p&gt;Happy Hacking !&lt;/p&gt;

</description>
      <category>security</category>
      <category>mfa</category>
      <category>sso</category>
      <category>caac</category>
    </item>
    <item>
      <title>The seven rules for continuous UnitTest</title>
      <dc:creator>koduki</dc:creator>
      <pubDate>Sun, 07 Oct 2018 03:33:07 +0000</pubDate>
      <link>https://dev.to/koduki/the-seven-rules-for-continuous-unittest-4j9l</link>
      <guid>https://dev.to/koduki/the-seven-rules-for-continuous-unittest-4j9l</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Do you write UnitTest on your project? Are UnitTests ran every time?&lt;/p&gt;

&lt;p&gt;I completely thought it's same thing to write UnitTest and write "continuous" UnitTest.&lt;br&gt;
But it is difference.&lt;/p&gt;

&lt;p&gt;Almost engineer know UnitTest is important. So they write UnitTest.&lt;br&gt;
But I saw such a UnitTest is abolish again and again.&lt;br&gt;
Why? Because they are very slow, they are difficult to maintenance, and they are broken.&lt;/p&gt;

&lt;p&gt;Continuous UnitTest needs to meet some requirements.&lt;br&gt;
You can satisify this requireents by the following rules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run always&lt;/li&gt;
&lt;li&gt;Keep portability&lt;/li&gt;
&lt;li&gt;Keep repeatability&lt;/li&gt;
&lt;li&gt;Avoid slow tests like a RDB, emulation, and so on&lt;/li&gt;
&lt;li&gt;Don't use your eyes&lt;/li&gt;
&lt;li&gt;One UnitTest, One point of view for a test&lt;/li&gt;
&lt;li&gt;Use readable name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, I explain about these rules.&lt;br&gt;
I explain based on Java, Maven, JUnit. But You can apply to other languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  The seven rules
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Run always
&lt;/h3&gt;

&lt;p&gt;This rule is the most important.&lt;br&gt;
You should run UnitTest every time, when you build your code.&lt;/p&gt;

&lt;p&gt;Don't use &lt;code&gt;-Dmaven.test.skip=true&lt;/code&gt;!! Please...&lt;/p&gt;

&lt;p&gt;If you can always run all unit tests, they are Continuous UnitTest code.&lt;br&gt;
But if you can't do it, you need modify it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep portability
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Portability&lt;/code&gt; is important.&lt;br&gt;
Unit Test isn't only ran on you PC, but also is ran on other environment.&lt;br&gt;
Other environment is coworker's PC, CI environment and future your PC.&lt;/p&gt;

&lt;p&gt;For portability, you need to only use under your project directory.&lt;br&gt;
You shouldn't use &lt;code&gt;/var/foobar&lt;/code&gt; and &lt;code&gt;D:\foobar&lt;/code&gt; as test data directory and so on.&lt;br&gt;
Please use under &lt;code&gt;target&lt;/code&gt; directory or &lt;code&gt;src/test/resources/&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep repeatability
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Portability&lt;/code&gt; is important for &lt;code&gt;run always&lt;/code&gt;.&lt;br&gt;
Your code should be ran without any manual operations like a removing test data and so on.&lt;/p&gt;

&lt;p&gt;In generally, such a initialize or cleanup code should be ran on &lt;code&gt;setUp&lt;/code&gt; or &lt;code&gt;tearDown&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Avoid slow tests like a RDB, emulation, and so on
&lt;/h3&gt;

&lt;p&gt;You should avoid slow test like a RDB test and using emulator.&lt;br&gt;
Such a test is very useful. You should do it. However it's integration test.&lt;/p&gt;

&lt;p&gt;JUnit also support integration test.&lt;br&gt;
You can use real DB by DBUnit. You can use arquillian. Today, you can use even Docker.&lt;/p&gt;

&lt;p&gt;I love it. But these test is slow. &lt;br&gt;
If tests are slow, you will not run all UnitTest every time.&lt;/p&gt;

&lt;p&gt;So, you should separate such a test as Slow Test.&lt;br&gt;
I recommend make a &lt;code&gt;slow-test&lt;/code&gt; profile or use &lt;code&gt;maven's integration-test phase&lt;/code&gt;.&lt;br&gt;
And you can ran it when build on CI environment or before commit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't use your eyes
&lt;/h3&gt;

&lt;p&gt;Don't use your eyes for UnitTest!&lt;/p&gt;

&lt;p&gt;UnitTest should check assertion automatically.&lt;br&gt;
You shouldn't use your eyes to check logs, standard out, file output and so on.&lt;br&gt;
Please use assertThat, assertEquals and so on. It's JUnit's role.&lt;/p&gt;

&lt;p&gt;Maybe following article helps you.&lt;br&gt;
&lt;a href="https://dev.to/koduki/how-do-you-write-production-code-for-unittest-5f30"&gt;How do you write "Production Code" for UnitTest?&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  One UnitTest, One UnitTest, One point of view for a test
&lt;/h3&gt;

&lt;p&gt;Each test should be check only one point of view.&lt;br&gt;
If there are many points of view for a test case, it's difficult to check which test is failed.&lt;/p&gt;

&lt;p&gt;This is not manual tests. You don't need to decrease test operation cost.&lt;br&gt;
You can make a test case for only one point of view.&lt;/p&gt;

&lt;p&gt;Please avoid only one test case per method.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use readable name
&lt;/h3&gt;

&lt;p&gt;Please use readable name.&lt;br&gt;
You should avoid like a &lt;code&gt;test001&lt;/code&gt;, &lt;code&gt;test002&lt;/code&gt;, &lt;code&gt;test003&lt;/code&gt;...&lt;br&gt;
Because anyone can't understand a expectation of its method.&lt;/p&gt;

&lt;p&gt;Naming is important as well as production code.&lt;/p&gt;

&lt;p&gt;Maybe BDD style helps you a lot.&lt;br&gt;
You should use method name, condition and expectation as test name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;I think almost rule is not difficult.&lt;br&gt;
Maybe many people think almost rules are very natural.&lt;br&gt;
You may even think it is unnecessary as it is common sense.&lt;/p&gt;

&lt;p&gt;But it's important to be clearly rules.&lt;/p&gt;

&lt;p&gt;Especially, many people don't separate UnitTest and IntegrationTest.&lt;br&gt;
JUnit tests are managed as just JUnit tests. It's not good.&lt;/p&gt;

&lt;p&gt;I believe simple rules support smooth communication!&lt;/p&gt;

&lt;p&gt;Happy hacking!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>java</category>
      <category>beginners</category>
      <category>junit</category>
    </item>
    <item>
      <title>How do you write "Production Code" for UnitTest?</title>
      <dc:creator>koduki</dc:creator>
      <pubDate>Sun, 30 Sep 2018 22:48:53 +0000</pubDate>
      <link>https://dev.to/koduki/how-do-you-write-production-code-for-unittest-5f30</link>
      <guid>https://dev.to/koduki/how-do-you-write-production-code-for-unittest-5f30</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;UnitTest is very important for keeping code quality.&lt;br&gt;
So almost project require to write UnitTest.&lt;/p&gt;

&lt;p&gt;As a result, I will review strange UnitTest or I will be asked them about "I can't write UnitTest!".&lt;/p&gt;

&lt;p&gt;Why? Because they don't consider about production code for UnitTest.&lt;br&gt;
They only consider about UnitTest code for UnitTest. This is not good.&lt;/p&gt;

&lt;p&gt;We should divid "business logic" and "uncontrolled value" from production code for writing UnitTest. This is also good for "readability".&lt;/p&gt;

&lt;p&gt;Basic rule is only two.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sepalate "business logic" and "uncontrolled value like a I/O, date, random"&lt;/li&gt;
&lt;li&gt;Inject dependency by argument, constructer, non-private fields&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, I explain how do you write production code for UnitTest.&lt;/p&gt;
&lt;h2&gt;
  
  
  Typically example
&lt;/h2&gt;

&lt;p&gt;Firstly, I explain typically cases.&lt;/p&gt;
&lt;h3&gt;
  
  
  Case 01: "I want to output to standard output"
&lt;/h3&gt;

&lt;p&gt;You should sepalate the logic and the output method like a &lt;code&gt;System.out.println&lt;/code&gt; or &lt;code&gt;Logger.info&lt;/code&gt;.&lt;br&gt;
You make a simple method for building "output string".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Production Code:&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example01Good&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;makeMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;makeMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// UnitTest Code:&lt;/span&gt;

&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testMakeMessage&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example01Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Case 02: "I want to use random number"
&lt;/h3&gt;

&lt;p&gt;Random number is not able to fix result.&lt;br&gt;
So we need to sepalate the logic and the number generator.&lt;br&gt;
This is a simple dice game logic for checking "Odd" or "Even"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Production Code:&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example02Good&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;throwDice&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;random&lt;/span&gt;&lt;span class="o"&gt;())));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s"&gt;"Win"&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Lose"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;throwDice&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Test Code:&lt;/span&gt;

&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testCheck&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example02Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Lose"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example02Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Win"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example02Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Lose"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example02Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Win"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example02Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Lose"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example02Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Win"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Case 03: "I want to calcurate calendar like tomorrow, 1 year ago or later"
&lt;/h3&gt;

&lt;p&gt;Calculating calendar is very general code. But &lt;code&gt;current time&lt;/code&gt; like &lt;code&gt;today&lt;/code&gt; is uncontrolled value.&lt;br&gt;
You need to sepalate the calendar Calculation logic and getting &lt;code&gt;current time&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can use &lt;code&gt;method arguments&lt;/code&gt; like a random number. This is good pracitice.&lt;br&gt;
But sometimes &lt;code&gt;getting current time&lt;/code&gt; is used on many places. In such a case, you can also use &lt;code&gt;factory pattern&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Production Code&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SystemDate&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;today&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;now&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example03Good&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;SystemDate&lt;/span&gt; &lt;span class="n"&gt;systemDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SystemDate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;tomorrow2&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;systemDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;today&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;plusDays&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Test Code&lt;/span&gt;

&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testTomorrow2&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Example03Good&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Example03Good&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;systemDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SystemDate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;today&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;tomorrow2&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Case 04: "I want to manage File I/O"
&lt;/h3&gt;

&lt;p&gt;Basically, this is same with Standard I/O case. You should sepalate the logic for &lt;code&gt;building Text or Binary&lt;/code&gt; and the logic for read or write.&lt;br&gt;
This is pretiy good.&lt;/p&gt;

&lt;p&gt;But sometimes you need very many text size, checking line order and so on.&lt;br&gt;
In such a case, you can use Reader/Writer and InputStream/OutputStream to sepalate logic and I/O.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Production Code&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example04Good&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Files&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newBufferedReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Paths&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"intput.txt"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
                &lt;span class="nc"&gt;Writer&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Files&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newBufferedWriter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Paths&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"output.txt"&lt;/span&gt;&lt;span class="o"&gt;));)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;addLineNumber&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;addLineNumber&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Writer&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BufferedReader&lt;/span&gt; &lt;span class="n"&gt;br&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="nc"&gt;PrintWriter&lt;/span&gt; &lt;span class="n"&gt;pw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PrintWriter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;);)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;br&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;br&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;pw&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;": "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Test Code&lt;/span&gt;

&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testAddLineNumber&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Writer&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringWriter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;addLineNumber&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"a\nb\nc\n"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;actuals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;split&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lineSeparator&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;actuals&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;actuals&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"1: a"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;actuals&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2: b"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;actuals&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"3: c"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fundamental Concept
&lt;/h2&gt;

&lt;p&gt;In this section, I explain more deeply.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sepalate logic and I/O
&lt;/h3&gt;

&lt;p&gt;Most importantly, you should seplate logic and I/O every time.&lt;br&gt;
This is important desigin for UnitTest.&lt;/p&gt;

&lt;p&gt;Let's take an example of a simple program for "getting text from command line arguments and print out to standard out".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example01Bad&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;//         String message = "World"; // for debug.&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe, this is the most simple code. I beleave you write down same code firstly.&lt;br&gt;
&lt;code&gt;for debug&lt;/code&gt; comment is funny.&lt;/p&gt;

&lt;p&gt;Next, let's write UnitTest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * Super bad code
 */&lt;/span&gt;
&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testMain&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="nc"&gt;Example01Bad&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a super simple. But there is NO assertion! So this UnitTest require to check True or False by your eyes!&lt;br&gt;
Do you think this is a joke? Unfortunatly, I see such a UnitTest on real project again and again...&lt;/p&gt;

&lt;p&gt;Of cource this code is terrible. More better people write blow code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * Bad code
 */&lt;/span&gt;
&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testMainWithSystemOut&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ByteArrayOutputStream&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ByteArrayOutputStream&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setOut&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PrintStream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="nc"&gt;Example01Bad&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lineSeparator&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code hook StandardOut. It is not bad.&lt;br&gt;
You can run it as UnitTest perfectly. But it's complex jsut a little.&lt;/p&gt;

&lt;p&gt;If you can't modify target production code, you should write it.&lt;br&gt;
However if you can change production code, UnitTest becomes more easily.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Good production code&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example01Good&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;makeMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;makeMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I sepalate "building message logic" as makeMessage method. So UnitTest becomes following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Good test code&lt;/span&gt;
&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testMakeMessage&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Example01Good&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a very simple. And it's perfect as UnitTest.&lt;/p&gt;

&lt;p&gt;You might think it strange, because this code doesn't do any test about StandardOut.&lt;br&gt;
Exactly. But it's not necessary as UnitTest.&lt;/p&gt;

&lt;p&gt;Basically, Checking bussiness logic is the most impotantly in UnitTest.&lt;br&gt;
&lt;code&gt;Sysmte.out.println&lt;/code&gt; and Logging library is standard or popular library.&lt;br&gt;
That means their code quality is keeped by other tests. You are only careful about your business logcic.&lt;br&gt;
Of course, you also need to check about Standard Output and so on. But it is integration test.&lt;/p&gt;
&lt;h3&gt;
  
  
  Don't initilze uncontrolled values directly
&lt;/h3&gt;

&lt;p&gt;You should not initialize uncontrolled value like a randome number, date, RPC(WebAPI), DAO on your each method.&lt;br&gt;
Please apply the concept of DI(Dependency Injection).&lt;/p&gt;

&lt;p&gt;Let's take an example of a method for &lt;code&gt;calculating tomorrow&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example03Bad&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;tomorrow&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;now&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;plusDays&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Naturally, this code is not able to do UnitTest. Because &lt;code&gt;LocalDate.now()&lt;/code&gt; value changes every time.&lt;br&gt;
So &lt;code&gt;LocalDate.now()&lt;/code&gt; is uncontrolled value. This is a typical beginner's trap.&lt;br&gt;
You need to sepalate it from business logic. The most simple solution is to use method arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;tomorrow&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="n"&gt;today&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;today&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;plusDays&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So you can fix test code follwing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testTomorrow&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Example03Good&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Example03Good&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;tomorrow&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;)),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is enough. But if getting current time is used on many places, you can also factory method pattern and stub.&lt;br&gt;
Firstly, you make factory class which has a method &lt;code&gt;today()&lt;/code&gt; to return &lt;code&gt;LocalDate&lt;/code&gt;.&lt;br&gt;
Next, you set it on target code field.&lt;/p&gt;

&lt;p&gt;Return value of &lt;code&gt;today()&lt;/code&gt; is depends on implementation. In production, it is &lt;code&gt;LocalDate.now()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SystemDate&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;today&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;now&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example03Good&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;SystemDate&lt;/span&gt; &lt;span class="n"&gt;systemDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SystemDate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;tomorrow2&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;systemDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;today&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;plusDays&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In test code, you use stub instead of &lt;code&gt;LocalDate.now()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testTomorrow2&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Example03Good&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Example03Good&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;systemDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SystemDate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="nf"&gt;today&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="n"&gt;assertThat&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;tomorrow2&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2017&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key is to use &lt;code&gt;package scope&lt;/code&gt; instead of &lt;code&gt;private scope&lt;/code&gt; or you should initialize by constructor.&lt;br&gt;
If you use private scope, you need a mock framework and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Basic rule is only two.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sepalate "business logic" and "uncontrolled value like a I/O, date, random"&lt;/li&gt;
&lt;li&gt;Inject dependency by argument, constructer, non-private fields&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not difficult. But sometimes biginner doesn't know it.&lt;br&gt;
In addtion, TDD(Test Driven Development) and Test First force you to write such code.&lt;br&gt;
It is a reasn that TDD is populer. &lt;/p&gt;

&lt;p&gt;And functional language is more strict style about side effect. Let's try to study also it.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>java</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
