title: Want to Mock ValidationofToken in restcontroller junit testing
body: <p>Need to skip a Validation of token id login in controller for unit testing</p>
  
  <p>Not sure what to use Mock or spy since i'm testing the controller itself</p>
  
  <pre><code>public class TestController extends BaseController {
  
      @Autowired
      TestService service;    
  
      @RequestMapping(value = "/test")
      public @ResponseBody TestResponse getAll(@RequestBody TestRequest request) {
  
          validateToken(request);
          TestResponse response = service.getall(request);
          response.setTokenID(request.getTokenID());
          return response;
      }   
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class BaseController {
  
      protected void validateToken(IRequest request) {
  
          TokenResponse tokenresponse = restTemplate.exchange(TokenServiceURL, HttpMethod.GET, null, TokenResponse .class, tokenId).getBody();
          User user = new user()
          user.setUserRole(tokenresponse.getUser()));
          request.setUser(user);
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class TestControllerTest {
  
      private MockMvc mockMvc;
  
      @Autowired
          private WebApplicationContext wac;
  
      @Autowired
      private TestController testControlller;
  
      @MockBean
          private TestService testService;
  
      BaseController baseControllerSpy = Mockito.spy(BaseController.class);
  
  
      @Before
      public void setUp(){
           MockitoAnnotations.initMocks(this);        
               mockMvc =  MockMvcBuilders.webAppContextSetup(wac).build();
      }
  
  
      @Test
      public void verifygetAll() throws Exception {
          TestRequest request = new TestRequest();        
          TestResponse response = new Response();     
  
          **Mockito.doNothing().when(baseControllerSpy).validateTokenID(request);**
          when(testService.get(request)).thenReturn(response);
  
          mockMvc.perform(MockMvcRequestBuilders.post("/test")
          .contentType(MediaType.APPLICATION_JSON)
          .content(requestString)
          .accept(MediaType.APPLICATION_JSON))
          .andExpect(status().isOk())
      }
  </code></pre>
  
  <h2>    }</h2>
  
  <p>Base controller being spy doesn't seem to work, is there any other way i can approach this scenrio. please help</p>