<commit_before>/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockitousage.stubbing;

import static org.mockito.Mockito.*;

import org.junit.Test;
import org.mockito.TestBase;
import org.mockito.MockitoAnnotations.Mock;
import org.mockito.exceptions.base.MockitoException;
import org.mockitousage.IMethods;

public class StubbingConsecutiveReturnValuesTest extends TestBase {

    @Mock private IMethods mock;
   
    @Test
    public void shouldReturnConsecutiveValues() throws Exception {
        stub(mock.simpleMethod())
            .toReturn("one")
            .toReturn("two")
            .toReturn("three");
        
        assertEquals("one", mock.simpleMethod());
        assertEquals("two", mock.simpleMethod());
        assertEquals("three", mock.simpleMethod());
        assertEquals("three", mock.simpleMethod());
        assertEquals("three", mock.simpleMethod());
    }
    
    @Test
    public void shouldThrowConsecutively() throws Exception {
        stub(mock.simpleMethod())
            .toThrow(new RuntimeException())
            .toThrow(new IllegalArgumentException())
            .toThrow(new NullPointerException());

        try {
            mock.simpleMethod();
            fail();
        } catch (RuntimeException e) {}
        
        try {
            mock.simpleMethod();
            fail();
        } catch (IllegalArgumentException e) {}
        
        try {
            mock.simpleMethod();
            fail();
        } catch (NullPointerException e) {}
        
        try {
            mock.simpleMethod();
            fail();
        } catch (NullPointerException e) {}
    }
    
    @Test
    public void shouldMixConsecutiveReturnsWithExcepions() throws Exception {
        stub(mock.simpleMethod())
            .toThrow(new IllegalArgumentException())
            .toReturn("one")
            .toThrow(new NullPointerException())
            .toReturn(null);
        
        try {
            mock.simpleMethod();
            fail();
        } catch (IllegalArgumentException e) {}
        
        assertEquals("one", mock.simpleMethod());
        
        try {
            mock.simpleMethod();
            fail();
        } catch (NullPointerException e) {}
        
        assertEquals(null, mock.simpleMethod());
        assertEquals(null, mock.simpleMethod());
    }
    
    @Test(expected=MockitoException.class)
    public void shouldValidateConsecutiveException() throws Exception {
        stub(mock.simpleMethod())
            .toReturn("one")
            .toThrow(new Exception());
    }
}<commit_msg>added test method for fut<commit_after>/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockitousage.stubbing;

import static org.mockito.Mockito.*;

import org.junit.Test;
import org.mockito.TestBase;
import org.mockito.MockitoAnnotations.Mock;
import org.mockito.exceptions.base.MockitoException;
import org.mockitousage.IMethods;

public class StubbingConsecutiveReturnValuesTest extends TestBase {

    @Mock private IMethods mock;
   
    @Test
    public void shouldReturnConsecutiveValues() throws Exception {
        stub(mock.simpleMethod())
            .toReturn("one")
            .toReturn("two")
            .toReturn("three");
        
        assertEquals("one", mock.simpleMethod());
        assertEquals("two", mock.simpleMethod());
        assertEquals("three", mock.simpleMethod());
        assertEquals("three", mock.simpleMethod());
        assertEquals("three", mock.simpleMethod());
    }
    
    @Test
    public void shouldThrowConsecutively() throws Exception {
        stub(mock.simpleMethod())
            .toThrow(new RuntimeException())
            .toThrow(new IllegalArgumentException())
            .toThrow(new NullPointerException());

        try {
            mock.simpleMethod();
            fail();
        } catch (RuntimeException e) {}
        
        try {
            mock.simpleMethod();
            fail();
        } catch (IllegalArgumentException e) {}
        
        try {
            mock.simpleMethod();
            fail();
        } catch (NullPointerException e) {}
        
        try {
            mock.simpleMethod();
            fail();
        } catch (NullPointerException e) {}
    }
    
    @Test
    public void shouldMixConsecutiveReturnsWithExcepions() throws Exception {
        stub(mock.simpleMethod())
            .toThrow(new IllegalArgumentException())
            .toReturn("one")
            .toThrow(new NullPointerException())
            .toReturn(null);
        
        try {
            mock.simpleMethod();
            fail();
        } catch (IllegalArgumentException e) {}
        
        assertEquals("one", mock.simpleMethod());
        
        try {
            mock.simpleMethod();
            fail();
        } catch (NullPointerException e) {}
        
        assertEquals(null, mock.simpleMethod());
        assertEquals(null, mock.simpleMethod());
    }
    
    @Test(expected=MockitoException.class)
    public void shouldValidateConsecutiveException() throws Exception {
        stub(mock.simpleMethod())
            .toReturn("one")
            .toThrow(new Exception());
    }
    
    @Test
    public void shouldAllowConsecutiveStubbingForVoidMethod() throws Exception {
        //TODO implement me!
//        stubVoid(mock)
//            .toThrow(new IllegalArgumentException())
//            .toReturn()
//            .toThrow(new NullPointerException())
//            .toReturn();
//        
//        try {
//            mock.simpleMethod();
//            fail();
//        } catch (IllegalArgumentException e) {}
    }
}
{'fraction_non_alphanumeric': 0.1124024284475282, 'fraction_numerical': 0.0013876843018213356, 'mean_word_length': 2.0427440633245384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542677', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1448, 'n_words': 306}