During running of Tests when your environment is not fully set to send email. the setUserActivationKey_shouldCreateUserActivationKey after setting the activation key as expected throws a message exception. So this issue is about catching the exception that is thrown Or adding to the function to expect that exception during test environment.
This line generating the error is https://github.com/openmrs/openmrs-core/blob/master/api/src/test/java/org/openmrs/api/UserServiceTest.java#L1406 ,
So instead of asserting if the returned user by the setUserActivationKey is the same as the createdUser check instead for the MessageException that will be thrown by that function since when no email is provided or assuming your system is not fully configured to send emails when the function tries to send an email it fails with a message exception. and to guarantee that the function does what its supposed to do the following line asserts that the activation key was created.
Similar implimentation can be found here