1/* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5package org.mockito.internal.invocation; 6 7import org.junit.Test; 8import org.mockito.internal.verification.InOrderContextImpl; 9import org.mockito.invocation.Invocation; 10import org.mockito.invocation.MatchableInvocation; 11import org.mockitoutil.TestBase; 12 13import java.util.Arrays; 14import java.util.concurrent.atomic.AtomicReference; 15 16import static junit.framework.TestCase.*; 17 18public class InvocationMarkerTest extends TestBase { 19 20 @Test 21 public void shouldMarkInvocationAsVerified() { 22 //given 23 Invocation i = new InvocationBuilder().toInvocation(); 24 InvocationMatcher im = new InvocationBuilder().toInvocationMatcher(); 25 assertFalse(i.isVerified()); 26 27 //when 28 InvocationMarker.markVerified(Arrays.asList(i), im); 29 30 //then 31 assertTrue(i.isVerified()); 32 } 33 34 @Test 35 public void shouldCaptureArguments() { 36 //given 37 Invocation i = new InvocationBuilder().toInvocation(); 38 final AtomicReference<Invocation> box = new AtomicReference<Invocation>(); 39 MatchableInvocation c = new InvocationMatcher(i) { 40 public void captureArgumentsFrom(Invocation i) { 41 box.set(i); 42 }}; 43 44 //when 45 InvocationMarker.markVerified(Arrays.asList(i), c); 46 47 //then 48 assertEquals(i, box.get()); 49 } 50 51 @Test 52 public void shouldMarkInvocationsAsVerifiedInOrder() { 53 //given 54 InOrderContextImpl context = new InOrderContextImpl(); 55 56 Invocation i = new InvocationBuilder().toInvocation(); 57 InvocationMatcher im = new InvocationBuilder().toInvocationMatcher(); 58 assertFalse(context.isVerified(i)); 59 assertFalse(i.isVerified()); 60 61 //when 62 InvocationMarker.markVerifiedInOrder(Arrays.asList(i), im, context); 63 64 //then 65 assertTrue(context.isVerified(i)); 66 assertTrue(i.isVerified()); 67 } 68} 69