When I mock the class in the following way(in Kotlin) val card: Card = mock<Card>()
it automatically initializes all its parameters(cardNumber,expMonth,expYear,CVC) as String, since they are saved as String. However in the code(Java) which I am about to test I initialize class card in the following way Card card = new Card(mView.getCreditCardNumber(), Integer.valueOf(mView.getMonth()), Integer.valueOf(mView.getYear()), mView.getCVV());
I already mocked those values in the following way whenever(mView.creditCardNumber).then { "1234567890123456" } whenever(mView.month).then { "12" } whenever(mView.year).then { "2022" } whenever(mView.cvv).then { "123" }
So the difference is that middle 2 parameters should be Integers, while I can not do that. I tried the following solution whenever(mView.month).then { 12 } whenever(mView.year).then { 2022 }
But I got CastException from Int to String. Since mView.month/year are supposed to be Strings.
So, is there a way to make this cast, otherwise I am not able to correctly test the rest of a code. Please help, or I am going crazy. Thanks :) !
Aucun commentaire:
Enregistrer un commentaire