mockito

Why is scalatest MockitoSugar deprecated?

谁都会走 提交于 2021-01-02 14:02:33
问题 I'm new to writing junit tests in Scala and I'm using Mockito to mock objects. I'm also using scalatest_2.12-3.0.4 . The ScalaTest documentation (like here) shows the syntax to create the mock using MockitoSugar, i.e. val mockCollaborator = mock[Collaborator] Eclipse shows org.scalatest.mock.MockitoSugar crossed out in the import statement, indicating it is deprecated. The only alternative I've found is, don't use MockitoSugar and instead do: val mockCollaborator = mock(classOf[Collaborator])

Why is scalatest MockitoSugar deprecated?

不问归期 提交于 2021-01-02 14:00:11
问题 I'm new to writing junit tests in Scala and I'm using Mockito to mock objects. I'm also using scalatest_2.12-3.0.4 . The ScalaTest documentation (like here) shows the syntax to create the mock using MockitoSugar, i.e. val mockCollaborator = mock[Collaborator] Eclipse shows org.scalatest.mock.MockitoSugar crossed out in the import statement, indicating it is deprecated. The only alternative I've found is, don't use MockitoSugar and instead do: val mockCollaborator = mock(classOf[Collaborator])

How to correctly mock ViewModel on androidTest

别等时光非礼了梦想. 提交于 2020-12-29 05:24:05
问题 I'm currently writing some UI unit tests for a fragment, and one of these @Test is to see if a list of objects is correctly displayed, this is not an integration test, therefore I wish to mock the ViewModel . The fragment's vars: class FavoritesFragment : Fragment() { private lateinit var adapter: FavoritesAdapter private lateinit var viewModel: FavoritesViewModel @Inject lateinit var viewModelFactory: FavoritesViewModelFactory (...) Here's the code: @MediumTest @RunWith(AndroidJUnit4::class)

How to correctly mock ViewModel on androidTest

空扰寡人 提交于 2020-12-29 05:23:19
问题 I'm currently writing some UI unit tests for a fragment, and one of these @Test is to see if a list of objects is correctly displayed, this is not an integration test, therefore I wish to mock the ViewModel . The fragment's vars: class FavoritesFragment : Fragment() { private lateinit var adapter: FavoritesAdapter private lateinit var viewModel: FavoritesViewModel @Inject lateinit var viewModelFactory: FavoritesViewModelFactory (...) Here's the code: @MediumTest @RunWith(AndroidJUnit4::class)

How to match a possible null parameter in Mockito

久未见 提交于 2020-12-28 05:45:02
问题 I'm trying to verify that the class I'm testing calls the correct dependency class's method. So I'm trying to match the method parameters, but I don't really care about the actual values in this test, because I don't want to make my test brittle. However, I'm running into trouble setting it up because Mockito has decided that the behaviour I'm expecting is a bug: https://github.com/mockito/mockito/issues/134 So what't the correct way to define an ArgumentMatcher for a parameter that might be

How to match a possible null parameter in Mockito

半腔热情 提交于 2020-12-28 05:41:05
问题 I'm trying to verify that the class I'm testing calls the correct dependency class's method. So I'm trying to match the method parameters, but I don't really care about the actual values in this test, because I don't want to make my test brittle. However, I'm running into trouble setting it up because Mockito has decided that the behaviour I'm expecting is a bug: https://github.com/mockito/mockito/issues/134 So what't the correct way to define an ArgumentMatcher for a parameter that might be

Mockito: Mock object which is no member but is created inline

青春壹個敷衍的年華 提交于 2020-12-26 08:59:14
问题 I have a class which does the following: public class Transformer { public void transform(final Car car) throws IOException { switch (car.getType()) { case OFFROAD: OffroadCar offroadCar = new OffroadTransformer().transform(car); // do something with offorad car break; ... } } } I have a test class: public class TransformerTest { @InjectMocks private Transformer transformer; @Mock private OffroadTransformer offroadTransformer; @BeforeEach public void setup() MockitoAnnotations.initMocks(this)

Mockito 'Misplaced argument detected here' in Java

﹥>﹥吖頭↗ 提交于 2020-12-25 01:39:05
问题 So I have this Mockito unit test: @Test public void createCard() { when(jwtServiceMock.getId(anyString())).thenReturn(validUserToken); when(profileServiceMock.getProfile(validUserToken)).thenReturn(mock(Profile.class)); when(cardServiceMock.countViewableCardsCreatedOrOwnedBy(anyObject())).thenReturn(5L); when(cardServiceMock.countCardsCreatedOrOwned(anyObject())).thenReturn(10L); final Card expectedCard = getCard(); when(cardServiceMock.createCard(anyString(), anyListOf(String.class),

Mockito 'Misplaced argument detected here' in Java

萝らか妹 提交于 2020-12-25 01:32:34
问题 So I have this Mockito unit test: @Test public void createCard() { when(jwtServiceMock.getId(anyString())).thenReturn(validUserToken); when(profileServiceMock.getProfile(validUserToken)).thenReturn(mock(Profile.class)); when(cardServiceMock.countViewableCardsCreatedOrOwnedBy(anyObject())).thenReturn(5L); when(cardServiceMock.countCardsCreatedOrOwned(anyObject())).thenReturn(10L); final Card expectedCard = getCard(); when(cardServiceMock.createCard(anyString(), anyListOf(String.class),

Mockito in maven using JPMS cannot access a member of class with modifiers “private”

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-15 06:25:10
问题 I am migrating a codebase to Java 11 and JPMS / Jigsaw and am having some trouble with mocking. This is the test I am trying to run. import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit