12637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpackage org.mockitousage.bugs.creation;
22637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
32637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.junit.Test;
42637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.junit.experimental.runners.Enclosed;
52637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.junit.runner.RunWith;
62637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.MockitoAnnotations;
72637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.Spy;
82637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
92637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport java.util.Random;
102637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
112637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin@RunWith(Enclosed.class)
122637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpublic class ConstructorInvokingMethodShouldNotRaiseExceptionTest {
132637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
142637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public static class WithDumbMethod {
152637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        @Spy
162637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        HasConstructorInvokingMethod hasConstructorInvokingMethod;
172637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
182637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        @Test
192637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        public void should_be_able_to_create_spy() throws Exception {
202637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            MockitoAnnotations.initMocks(this);
212637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
222637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
232637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        private static class HasConstructorInvokingMethod {
242637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            public HasConstructorInvokingMethod() { someMethod(); }
252637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
262637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            void someMethod() { }
272637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
282637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
292637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
302637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public static class UsingMethodObjectReferenceResult {
312637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        @Spy
322637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        HasConstructorInvokingMethod hasConstructorInvokingMethod;
332637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
342637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        @Test
352637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        public void should_be_able_to_create_spy() throws Exception {
362637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            MockitoAnnotations.initMocks(this);
372637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
382637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
392637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        private static class HasConstructorInvokingMethod {
402637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            private final boolean doesIt;
412637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            public HasConstructorInvokingMethod() {
422637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin                doesIt = someMethod().contains("yup");
432637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            }
442637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
452637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            String someMethod() { return "tada!"; }
462637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
472637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
482637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
492637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public static class UsingMethodPrimitiveResult {
502637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        @Spy
512637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        HasConstructorInvokingMethod hasConstructorInvokingMethod;
522637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
532637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        @Test
542637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        public void should_be_able_to_create_spy() throws Exception {
552637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            MockitoAnnotations.initMocks(this);
562637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
572637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
582637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        private static class HasConstructorInvokingMethod {
592637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            private final boolean doesIt;
602637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            public HasConstructorInvokingMethod() {
612637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin                doesIt = someMethod();
622637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            }
632637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
642637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            boolean someMethod() { return new Random().nextBoolean(); }
652637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
662637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
672637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin}
68