BAEL-3854 - Pattern Matching for instanceof in Java 14 - add unit test

This commit is contained in:
Jonathan Cook 2020-03-02 22:35:53 +01:00
parent f0e23cabda
commit 09e5ac39cf
2 changed files with 38 additions and 5 deletions

View File

@ -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() {
}
}

View File

@ -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();
}
}