BAEL-3854 - Pattern Matching for instanceof in Java 14 - add unit test
This commit is contained in:
parent
f0e23cabda
commit
09e5ac39cf
|
@ -10,16 +10,16 @@ public class PatternMatchingForInstanceOf {
|
|||
}
|
||||
}
|
||||
|
||||
private abstract class Animal {
|
||||
abstract class Animal {
|
||||
}
|
||||
|
||||
private final class Cat extends Animal {
|
||||
private void meow() {
|
||||
final class Cat extends Animal {
|
||||
void meow() {
|
||||
}
|
||||
}
|
||||
|
||||
private final class Dog extends Animal {
|
||||
private void woof() {
|
||||
final class Dog extends Animal {
|
||||
void woof() {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.baeldung.java14.patternmatchingforinstanceof;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.baeldung.java14.patternmatchingforinstanceof.PatternMatchingForInstanceOf.Cat;
|
||||
import com.baeldung.java14.patternmatchingforinstanceof.PatternMatchingForInstanceOf.Dog;
|
||||
|
||||
class PatternMatchingForInstanceOfUnitTest {
|
||||
|
||||
@Test
|
||||
void givenAnAnimal_whenTypeIsCat_ThenCatGoesMeow() {
|
||||
Cat animal = mock(Cat.class);
|
||||
|
||||
PatternMatchingForInstanceOf instanceOf = new PatternMatchingForInstanceOf();
|
||||
instanceOf.performAnimalOperations(animal);
|
||||
|
||||
verify(animal).meow();
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenAnAnimal_whenTypeIsDog_ThenDogGoesWoof() {
|
||||
Dog animal = mock(Dog.class);
|
||||
|
||||
PatternMatchingForInstanceOf instanceOf = new PatternMatchingForInstanceOf();
|
||||
instanceOf.performAnimalOperations(animal);
|
||||
|
||||
verify(animal).woof();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue