108bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann/* 208bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann * Copyright (c) 2017 Mockito contributors 308bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann * This program is made available under the terms of the MIT License. 408bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann */ 52637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpackage org.mockito.internal.junit; 62637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 72637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.internal.creation.settings.CreationSettings; 82637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.mock.MockCreationSettings; 92637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.quality.Strictness; 102637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 112637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin/** 122637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin * Fails early when mismatched arguments used for stubbing 132637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin */ 142637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpublic class StrictStubsRunnerTestListener implements MockitoTestListener { 152637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 162637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin private final DefaultStubbingLookupListener stubbingLookupListener = new DefaultStubbingLookupListener(Strictness.STRICT_STUBS); 172637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 182637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Override 192637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin public void testFinished(TestFinishedEvent event) {} 202637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 212637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Override 222637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin public void onMockCreated(Object mock, MockCreationSettings settings) { 232637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin //It is not ideal that we modify the state of MockCreationSettings object 242637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin //MockCreationSettings is intended to be an immutable view of the creation settings 252637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin //In future, we should start passing MockSettings object to the creation listener 262637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin //TODO #793 - when completed, we should be able to get rid of the CreationSettings casting below 272637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin ((CreationSettings) settings).getStubbingLookupListeners().add(stubbingLookupListener); 282637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin } 292637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin} 30