title: Junit Test cases for Save and Update using Spring Boot REST
body: <p>I've written a Test case to save &amp; update which as below,</p>
  <pre><code>@InjectMocks
  UserController uc;
  
  @Mock
  UserService userService;
  @Mock
  User user;
  
  @Test
  public void saveUser() throws Exception {
      SimpleDateFormat simpleformat = new SimpleDateFormat(&quot;yyyy-MM-dd hh:mm:s+ss&quot;);
      
      Long id= 2L;
      String userName = &quot;John&quot;;
      String passWord = &quot;john&quot;;
      Date otpSentDate = simpleformat.parse(&quot;2019-12-24 01:22:05+00&quot;);
      Date createdDate = simpleformat.parse(&quot;2019-12-24 01:22:05+00&quot;);
      Date updatedDate = simpleformat.parse(&quot;2019-12-24 01:22:05+00&quot;);
      user.setId(id);user.setUserName(userName);user.setPassWord(passWord);user.setOtpSentDate(otpSentDate);
      user.setCreatedDate(createdDate);user.setUpdatedDate(updatedDate);
      assertEquals(1, uc.saveUser(user));
  }
  
  @Test
  public void updateUser() throws Exception {
      SimpleDateFormat simpleformat = new SimpleDateFormat(&quot;yyyy-MM-dd hh:mm:s+ss&quot;);
      
      Long id= 2L;
      String userName = &quot;John&quot;;
      String passWord = &quot;john&quot;;
      Date otpSentDate = simpleformat.parse(&quot;2019-12-24 01:22:05+00&quot;);
      Date createdDate = simpleformat.parse(&quot;2019-12-24 01:22:05+00&quot;);
      Date updatedDate = simpleformat.parse(&quot;2019-12-24 01:22:05+00&quot;);
      user.setId(id);user.setUserName(userName);user.setPassWord(passWord);user.setOtpSentDate(otpSentDate);
      user.setCreatedDate(createdDate);user.setUpdatedDate(updatedDate);
      assertEquals(1, uc.updateUser(user));
  }
  </code></pre>
  <p>Controller for both methods are as below,</p>
  <pre><code> @PostMapping(&quot;/saveUser&quot;)
  public int saveUser(@RequestBody User user) throws Exception {
      if (user.getUserName() == &quot;&quot; || user.getPassWord() == &quot;&quot;) {
          throw new Exception(&quot;User name or Password should not be empty!&quot;);
      } else {
          userService.saveUser(user);
          System.out.println(&quot;Inserted data with id: &quot;+ user.getId());
      }
      return 1;
  }
  @PutMapping(&quot;/updateUser&quot;)
  public void updateUser(@RequestBody User user) {
      userService.updateUser(user);
      System.out.println(&quot;User with id &quot;+ user.getId() + &quot; updated successfully!&quot;);
  }
  </code></pre>
  <p>And ServiceImpl.java are as follows,</p>
  <pre><code>@Override
  public void saveUser(User user) {
      userMapper.saveUser(user);
  }
   @Override
  public void updateUser(User user) {
      userMapper.updateUser(user);
  }
  </code></pre>
  <p>After running above methods, I'm getting error as below,
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.naveen.MybatisApplicationTests': Unsatisfied dependency expressed through field 'user'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.naveen.entity.User' available: expected at least 1 bean which qualifies as autowire candidate.</p>