title: How to make a simple rest api controller test?
body: <p>So I am trying to make a test for the post method of my controller, but I keep finding tests from other people that do not work on my or their post methods are way more advanced.</p>
  <p><strong>My post method</strong></p>
  <pre><code>@Autowired
  PartyLeaderService partyleaderService;
  
  @PostMapping(&quot;/&quot;)
  public void add(@RequestBody PartyLeaderDto partyLeaderDto){
      partyLeaderService.savePartyLeader(partyLeaderDto);
  }
  </code></pre>
  <p>As you can see it is fairly simple, but I still can not seem to get it to work properly.
  I tried this method:</p>
  <pre><code>@Test
  public void testPostExample() {
      PartyLeaderDto partyLeaderDto = new PartyLeaderDto(1, &quot;arun&quot;, &quot;link&quot;);
  
      partyLeaderController.add(partyLeaderDto);
      Mockito.verify(partyLeaderController).add(partyLeaderDto);
  }
  </code></pre>
  <p>But SonarQube is saying that the method is still not covered by tests, so my test must be wrong.</p>
  <p><strong>My DTO</strong></p>
  <pre><code>@NoArgsConstructor
  @AllArgsConstructor
  @Getter
  @Setter
  @Builder
  public class PartyLeaderDto {
      private Integer id;
      private String name;
      private String apperance;
  }
  </code></pre>
  <p>Can anyone help me, because I think the answer is fairly simple, but I can't seem to find it.</p>