<?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: Edgar Cirilo</title>
    <description>The latest articles on DEV Community by Edgar Cirilo (@ecirilo).</description>
    <link>https://dev.to/ecirilo</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%2F493810%2Fb5f5cc84-7722-40ec-a146-fb4a81154733.png</url>
      <title>DEV Community: Edgar Cirilo</title>
      <link>https://dev.to/ecirilo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ecirilo"/>
    <language>en</language>
    <item>
      <title>Git cheat sheet</title>
      <dc:creator>Edgar Cirilo</dc:creator>
      <pubDate>Mon, 02 Nov 2020 09:39:15 +0000</pubDate>
      <link>https://dev.to/ecirilo/my-daily-git-575j</link>
      <guid>https://dev.to/ecirilo/my-daily-git-575j</guid>
      <description>&lt;p&gt;Git has become a basic tool in the software development lifecycle. And now, in an age where it seems the world is moving to a remote approach, mastering this skill will be of great advantage to all software professionals, since it makes you a better team player and improves the lifecycle.&lt;/p&gt;

&lt;p&gt;There are many blogs teaching Git. These are the ones that I highly recommend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials/setting-up-a-repository"&gt;Atlassian&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://anotheruiguy.gitbooks.io/gitforeveryone/content/index.html"&gt;Git for everyone&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Moreover, I want to share the most common commands that I use in my daily workflow. Note that all will be using the command line:&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the repo
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# It works with https or ssh&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clone &lt;span class="s1"&gt;'https://github.com/git/git.git'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Change Origin
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Sometimes we need to change the repo to other owner or location, &lt;/span&gt;
&lt;span class="c"&gt;# in order to avoid it to be cloned again, we can just change the remote origin.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git remote add origin &lt;span class="s1"&gt;'https://github.com/moby/moby.git'&lt;/span&gt;

&lt;span class="c"&gt;# We can verify the new remote is set correctly&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; origin  https://github.com/moby/moby.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; origin  https://github.com/moby/moby.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get the latest changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Get the latest changes in the remote repository with 'git pull'&lt;/span&gt;
&lt;span class="c"&gt;# Remember that specifying the remote 'origin' and the branch name is always a good practice&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git pull origin &amp;lt;branch-name&amp;gt;

&lt;span class="c"&gt;# Use 'git fetch' to sync your local repository with the remote repository&lt;/span&gt;
&lt;span class="c"&gt;# This only includes the metadata, new branches, tags, and tree history&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git fetch 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a new branch
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Move and create at the same time to a new branch&lt;/span&gt;
&lt;span class="c"&gt;# Tip: Use git-flow branch naming convention: feature/*, hotfix/* and so on.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add your changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add changes to Stage&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add &amp;lt;file-name&amp;gt;

&lt;span class="c"&gt;# Add ALL changes to Stage&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# Commit changes to the local repository&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Commit message"&lt;/span&gt;

&lt;span class="c"&gt;# Add all and commit at the same time (Only to tracked files)&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-am&lt;/span&gt; &lt;span class="s2"&gt;"Commit message"&lt;/span&gt;

&lt;span class="c"&gt;# Push commits to the remote repository&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix commits
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Wrong commit message? No problem. Edit last commit message&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"New commit message"&lt;/span&gt;

&lt;span class="c"&gt;# Did you forget some changes and don't want a new commit?&lt;/span&gt;
&lt;span class="c"&gt;# Add them to the last commit&lt;/span&gt;
&lt;span class="c"&gt;# Warning: Try not to use it a lot &lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;--no-edit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  See commit history
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Print commit tree in a pretty way&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt; &lt;span class="nt"&gt;--decorate&lt;/span&gt; &lt;span class="nt"&gt;--graph&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Save unfinished work
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Save all tracked files (Uncommitted)&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash

&lt;span class="c"&gt;#Save all tracked files with a message (Uncommitted)&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash push &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Great message"&lt;/span&gt;

&lt;span class="c"&gt;# Include untracked and ignored files&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash &lt;span class="nt"&gt;--all&lt;/span&gt; 

&lt;span class="c"&gt;# List saved work&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash list
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; stash@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;: WIP on submit: 6ebd0e2... Update git-stash documentation
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; stash@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;: On master: 9cc0589... Add git-stash

&lt;span class="c"&gt;# Apply last saved work to the working directory&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash pop

&lt;span class="c"&gt;# Apply specific saved work to the working directory&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash pop stash@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Clean stash&lt;/span&gt;
&lt;span class="c"&gt;# Warning: Be sure you don't need anything else before running this command&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Clean up a local repository
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# A lot of branches that do no longer exist in the remote repository?&lt;/span&gt;
&lt;span class="c"&gt;# Delete them from the local repository...&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git fetch &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Handling mistakes (Warning: use locally only)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Unstage file&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git reset HEAD &lt;span class="nt"&gt;--&lt;/span&gt; &amp;lt;file-name&amp;gt;

&lt;span class="c"&gt;# Unwanted changes now?, Sync with HEAD&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD

&lt;span class="c"&gt;# Want to start over? undo n-last commits&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  My git aliases
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# I'm using Windows, so, instead of use bash aliases I use the git config option&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.co&lt;span class="o"&gt;=&lt;/span&gt;checkout
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.br&lt;span class="o"&gt;=&lt;/span&gt;branch
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.cm&lt;span class="o"&gt;=&lt;/span&gt;commit
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.st&lt;span class="o"&gt;=&lt;/span&gt;status
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.unstage&lt;span class="o"&gt;=&lt;/span&gt;reset HEAD &lt;span class="nt"&gt;--&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.last&lt;span class="o"&gt;=&lt;/span&gt;log &lt;span class="nt"&gt;-1&lt;/span&gt; HEAD
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.po&lt;span class="o"&gt;=&lt;/span&gt;pull origin
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.ps&lt;span class="o"&gt;=!&lt;/span&gt;git push origin &lt;span class="si"&gt;$(&lt;/span&gt;git current&lt;span class="si"&gt;)&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.current&lt;span class="o"&gt;=&lt;/span&gt;branch &lt;span class="nt"&gt;--show-current&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.pu&lt;span class="o"&gt;=&lt;/span&gt;push origin
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.pl&lt;span class="o"&gt;=!&lt;/span&gt;git pull origin &lt;span class="si"&gt;$(&lt;/span&gt;git current&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>github</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Migrating from JUnit 4 to JUnit 5 with Spring Boot 2.3.x</title>
      <dc:creator>Edgar Cirilo</dc:creator>
      <pubDate>Tue, 27 Oct 2020 16:13:59 +0000</pubDate>
      <link>https://dev.to/ecirilo/migrating-from-junit-4-to-junit-5-with-spring-boot-2-3-x-1e02</link>
      <guid>https://dev.to/ecirilo/migrating-from-junit-4-to-junit-5-with-spring-boot-2-3-x-1e02</guid>
      <description>&lt;p&gt;Recently, our team has moved to the last release of Spring (2.3.4). So we are taking advantage to move some projects unit tests to JUnit 5 due this is the default version since Spring Boot 2.2.x. Even though Junit 5 includes a vintage engine to support the JUnit 3 and JUnit 4 versions, we decided to fully migrate to JUnit Jupiter.&lt;/p&gt;

&lt;h1&gt;
  
  
  Dependencies
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-test&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;exclusions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclusion&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.junit.vintage&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;junit-vintage-engine&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/exclusion&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/exclusions&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Annotations
&lt;/h1&gt;

&lt;p&gt;In the new version of JUnit, the base package has changed to &lt;code&gt;org.junit.jupiter.api&lt;/code&gt; and some annotations have changed. Below you will find a table with the mapping for the most used annotations.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;JUnit 4&lt;/th&gt;
&lt;th&gt;JUnit 5&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;org.junit.Test&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;org.junit.jupiter.api.Test&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;org.junit.Before&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;org.junit.jupiter.api.BeforeEach&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;org.junit.After&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;org.junit.jupiter.api.AfterEach&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;org.junit.BeforeClass&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;org.junit.jupiter.api.BeforeAll&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;org.junit.AfterClass&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;org.junit.jupiter.api.AfterAll&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here is the &lt;a href="https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/package-summary.html"&gt;API Documentation&lt;/a&gt; for the full list of annotations.&lt;/p&gt;

&lt;h1&gt;
  
  
  Exceptions
&lt;/h1&gt;

&lt;p&gt;When using JUnit 4, we used the ExpectedException rule. However, it is no longer supported by JUnit 5. Fortunately, the Assertions API included in the Jupiter package have a handy way to assert the exceptions.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;assertThrows()&lt;/code&gt; method asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.&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;static&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Throwable&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="nf"&gt;assertThrows&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Class&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;expectedType&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Executable&lt;/span&gt; &lt;span class="n"&gt;executable&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the exception is returned, we can use the preferred Assertions API. In our case, we use AssertJ, so it's pretty similar to any other object.&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;exampleMethod_ThrowsCustomException_Fail&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;CustomException&lt;/span&gt; &lt;span class="n"&gt;expectedException&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nc"&gt;Assertions&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;assertThrows&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CustomException&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ObjectDTO&lt;/span&gt; &lt;span class="n"&gt;dto&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;expectedException&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;isNotNull&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;expectedException&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getErrorCode&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;isEqualTo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&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;h1&gt;
  
  
  Spring
&lt;/h1&gt;

&lt;p&gt;Spring provides some convenient annotations on behalf of JUnit 5. &lt;br&gt;
&lt;code&gt;@SpringJUnitConfig&lt;/code&gt; combines &lt;code&gt;@ExtendWith(SpringExtension.class)&lt;/code&gt; and &lt;code&gt;@ContextConfiguration&lt;/code&gt; into a single annotation. So, we have access to the configuration options through the &lt;code&gt;@SpringJUnitConfig&lt;/code&gt; annotation.&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;@SpringJUnitConfig&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;classes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;TestConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SomeService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&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;SomeServiceTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// class body...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@SpringJUnitWebConfig&lt;/code&gt; is pretty similar, with the difference that it includes &lt;code&gt;@WebAppConfiguration&lt;/code&gt; besides &lt;code&gt;@ExtendWith(SpringExtension.class)&lt;/code&gt; and &lt;code&gt;@ContextConfiguration&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;@SpringJUnitWebConfig&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;classes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;WebConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SomeController&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&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;SomeControllerTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Autowired&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;WebApplicationContext&lt;/span&gt; &lt;span class="n"&gt;webAppContext&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// class body...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read the official documentation of &lt;a href="https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/testing.html#integration-testing-annotations-junit-jupiter"&gt;spring&lt;/a&gt; and &lt;a href="https://docs.spring.io/spring-boot/docs/2.3.4.RELEASE/reference/htmlsingle/#boot-features-testing"&gt;spring boot&lt;/a&gt; to see the full list of annotations and a full description of each one.&lt;/p&gt;

&lt;h1&gt;
  
  
  Mockito
&lt;/h1&gt;

&lt;p&gt;For Mockito, there are few changes to take into account. For previous versions, we used &lt;code&gt;@RunWith&lt;/code&gt; but for JUnit 5 we have to use &lt;code&gt;@ExtendWith&lt;/code&gt; instead:&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;@RunWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MockitoJUnitRunner&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&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;TheBestServiceTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// class body...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is now&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;@ExtendWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MockitoExtension&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&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;TheBestServiceTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// class body...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Statics
&lt;/h2&gt;

&lt;p&gt;Sometimes we need to mock some static methods. Usually, we use Powermock for this purpose. Nevertheless, Powermock won't be ported to the new version of JUnit. Fortunately, Mockito includes support for statics since the 3.4.x version.&lt;/p&gt;

&lt;p&gt;In this case, we need to add some extra dependencies since &lt;code&gt;spring-boot-starter-test&lt;/code&gt; only includes Mockito up to 3.3.3 version:&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.mockito&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mockito-junit-jupiter&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${mockito.version}&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.mockito&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mockito-inline&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${mockito.version}&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.mockito&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mockito-core&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${mockito.version}&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;p&gt;Now we can mock static methods! As a matter of fact, this works pretty much as the normal methods. Ee only need to use a generic class supplied by Mockito; &lt;code&gt;MockedStatic&amp;lt;T&amp;gt;&lt;/code&gt;, and use it within a &lt;code&gt;try&lt;/code&gt; clause:&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="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MockedStatic&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ClassWithStaticMethod&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mockedStatic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nc"&gt;Mockito&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mockStatic&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ClassWithStaticMethod&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;mockedStatic&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;ClassWithStaticMethod:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;someStaticMethod&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;thenReturn&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;SomeDTO&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;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I think JUnit 5 comes with a different approach than its past version, something quite interesting, which can help us improve our unit tests. Despite being a big change, JUnit 5 makes sure to have backward compatibility to make migration more manageable. However, I highly recommend taking that step whenever possible.&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>junit</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
