Using Mockito you stub the external service like this:
'when(mockedAuthenticationWebService.authenticate(username, password).thenReturn(yourStubbedReturnValue);'
I am writing this up from memory so forgive if it doesn't compile straight away; you'll get the idea.
Here, using Mockito, hamcrest and JUnit 4, I am also verifying that the service is called with the correct parameters, which your test will want to cover as well :)
@Test
public class UserAuthenticationTest {
// Given
UserAuthentication userAuthentication = new UserAuthentication();
AuthenticationWebService mockedAuthenticationWebService = mock(AuthenticationWebService.class)
String username = "aUsername" , password = "aPassword";
when(mockedAuthenticationWebService.authenticate(username, password).thenReturn(true); // but you could return false here too if your test needed it
userAuthentication.set(mockedAuthenticationWebService);
// When
boolean yourStubbedReturnValue = userAuthentication.authenticate(username, password);
//Then
verify(mockedAuthenticationWebService).authenticateUser(username, password);
assertThat(yourStubbedReturnValue, is(true));
}
Lastly, the fact that your class is @Autowired makes no difference to any of this.