Tests: protect InvocationOnMock#getArgument class cast exceptions

pull/711/head
pabloFuente 2022-03-24 23:08:25 +01:00
parent 80b097e379
commit ad152fab8e
1 changed files with 13 additions and 2 deletions

View File

@ -40,14 +40,25 @@ public class IntegrationTestConfiguration {
final KmsManager spy = Mockito.spy(new FixedOneKmsManager(new KurentoSessionManager(), new DummyLoadManager())); final KmsManager spy = Mockito.spy(new FixedOneKmsManager(new KurentoSessionManager(), new DummyLoadManager()));
doAnswer(invocation -> { doAnswer(invocation -> {
List<Kms> successfullyConnectedKmss = new ArrayList<>(); List<Kms> successfullyConnectedKmss = new ArrayList<>();
List<KmsProperties> kmsProperties = invocation.getArgument(0); List<KmsProperties> kmsProperties = null;
try {
kmsProperties = invocation.getArgument(0);
} catch (Exception e) {
System.err.println("Error getting argument from stubbed method: " + e.getMessage());
}
for (KmsProperties kmsProp : kmsProperties) { for (KmsProperties kmsProp : kmsProperties) {
Kms kms = new Kms(kmsProp, Whitebox.getInternalState(spy, "loadManager"), spy); Kms kms = new Kms(kmsProp, Whitebox.getInternalState(spy, "loadManager"), spy);
KurentoClient kClient = mock(KurentoClient.class); KurentoClient kClient = mock(KurentoClient.class);
doAnswer(i -> { doAnswer(i -> {
Thread.sleep((long) (Math.random() * 1000)); Thread.sleep((long) (Math.random() * 1000));
((Continuation<MediaPipeline>) i.getArgument(0)).onSuccess(mock(MediaPipeline.class)); Continuation<MediaPipeline> continuation = null;
try {
continuation = i.getArgument(0);
} catch (Exception e) {
System.err.println("Error getting argument from stubbed method: " + e.getMessage());
}
continuation.onSuccess(mock(MediaPipeline.class));
return null; return null;
}).when(kClient).createMediaPipeline((Continuation<MediaPipeline>) any()); }).when(kClient).createMediaPipeline((Continuation<MediaPipeline>) any());