JAVA-27645 Check article code matches github (#15323)
This commit is contained in:
+9
-9
@@ -11,55 +11,55 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
public class InstanceOfUnitTest {
|
||||
|
||||
@Test
|
||||
void giveWhenInstanceIsCorrect_thenReturnTrue() {
|
||||
void givenWhenInstanceIsCorrect_thenReturnTrue() {
|
||||
Ring ring = new Ring();
|
||||
assertTrue(ring instanceof Round);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenObjectIsInstanceOfType_thenReturnTrue() {
|
||||
void givenWhenObjectIsInstanceOfType_thenReturnTrue() {
|
||||
Circle circle = new Circle();
|
||||
assertTrue(circle instanceof Circle);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void giveWhenInstanceIsOfSubtype_thenReturnTrue() {
|
||||
void givenWhenInstanceIsOfSubtype_thenReturnTrue() {
|
||||
Circle circle = new Circle();
|
||||
assertTrue(circle instanceof Round);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenTypeIsInterface_thenReturnTrue() {
|
||||
void givenWhenTypeIsInterface_thenReturnTrue() {
|
||||
Circle circle = new Circle();
|
||||
assertTrue(circle instanceof Shape);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenTypeIsOfObjectType_thenReturnTrue() {
|
||||
void givenWhenTypeIsOfObjectType_thenReturnTrue() {
|
||||
Thread thread = new Thread();
|
||||
assertTrue(thread instanceof Object);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenInstanceValueIsNull_thenReturnFalse() {
|
||||
void givenWhenInstanceValueIsNull_thenReturnFalse() {
|
||||
Circle circle = null;
|
||||
assertFalse(circle instanceof Round);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenComparingClassInDiffHierarchy_thenCompilationError() {
|
||||
void givenWhenComparingClassInDiffHierarchy_thenCompilationError() {
|
||||
//assertFalse( circle instanceof Triangle);
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenStream_whenCastWithoutInstanceOfChk_thenGetException() {
|
||||
void givenWhenStream_whenCastWithoutInstanceOfChk_thenGetException() {
|
||||
Stream<Round> roundStream = Stream.of(new Ring(), new Ring(), new Circle());
|
||||
assertThrows(ClassCastException.class, () -> roundStream.map(it -> (Ring) it).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void giveWhenStream_whenCastAfterInstanceOfChk_thenGetExpectedResult() {
|
||||
void givenWhenStream_whenCastAfterInstanceOfChk_thenGetExpectedResult() {
|
||||
Stream<Round> roundStream = Stream.of(new Ring(), new Ring(), new Circle());
|
||||
List<Ring> ringList = roundStream.filter(it -> it instanceof Ring).map(it -> (Ring) it).collect(Collectors.toList());
|
||||
assertEquals(2, ringList.size());
|
||||
|
||||
Reference in New Issue
Block a user