title: How to write test so that the controller can connect to API?
body: <p>I'm trying to deal with Rest api tests.
  Well, the controller in my code connects to the external api parsing and returns in the form of JSON.
  I'm trying to run a test so that it returns the result of my application’s logic.
  Unfortunately, during testing I can't connect with api github.</p>
  
  <blockquote>
  <pre><code>java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;404&gt;
  Expected :200
  Actual   :404
  </code></pre>
  </blockquote>
  
  <pre><code>  @WebMvcTest(RepositoryDetailsController.class)
    @ContextConfiguration(classes = RepositoryDetailsController.class)
  
   class RepositoryDetailsControllerTestt {
      @Autowired
      private MockMvc mvc;
  
  
      @MockBean
      private RepositoryDetailsService service;
      @InjectMocks
      private RepositoryDetailsController repositoryDetailsController;
  
  
     @Before
      public void setUp() {
  
          mvc = MockMvcBuilders.standaloneSetup(repositoryDetailsController).build();
      }
  
      @Test
      public void mockTest() throws Exception {
  
          RepositoryDetailsResponse details = new RepositoryDetailsResponse();
          details.setDescription("Ruby toolkit for the GitHub API");
          details.set"https://github.com/octokit/octokit.rb.git");
          details.setStars("57892");
          details.setName("octokit/octokit.rb");
  
          mvc.perform(get("repository/{owner}/{repository}","octokit","octokit.rb")
                  .contentType(MediaType.APPLICATION_JSON))
                  .andExpect(status().isOk())
                  .andDo(print())
                  .andExpect(jsonPath("$.*", hasSize(5)))
                  .andExpect(jsonPath("$.fullName").value(details.getName()))
                  .andExpect(jsonPath("$.description").value(details.getDescription()))
                  .andExpect(jsonPath("$.cloneUrl").value(details.getUrl()))
                  .andExpect(jsonPath("$.stars").value(details.getStars()));
      }
  </code></pre>