döküm edilemez getApple()
yöntemi.mockito ClassCastException bir sahte I test etmek istiyorum sınıf <code>AppleProcessor</code> bir yöntemi vardır
Testim benziyor:
@Mock
FruitBasket fruitBasket;
@Mock
Fruit fruit;
@Mock
AppleFruit apple;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testAnAppleIsProcessed() {
AppleProcessor appleProcessor = new AppleProcessoer();
when(fruit.getType()).thenReturn(Fruit.APPLE);
when(((AppleFruit) fruit).getApple()).thenReturn(apple);
appleProcessor.process(fruit);
verify(fruitBasket).add(isA(Apple.class));
}
Ancak aşağıdaki hatayı alıyorum: testinde bu hattan gelen
java.lang.ClassCastException: package.fruit.Fruit$$EnhancerByMockitoWithCGLIB$$b8254f54 cannot be cast to package.fruit.AppleFruit
when(((AppleFruit) fruit).getApple()).thenReturn(apple);
misiniz kimse k şimdi bunu nasıl çözebilirim böylece kodumu test edebilirim?
Teşekkürler, test şimdi çalışıyor. – user2844485