Unbounded wildcard in generics

Unbounded wildcard: Java generics unbounded wildcards : Unbounded wildcard is used for list of unknown types using ‘?’(Type is not bounded). Syntax: List<?> Let us consider the below example: public static void printListItems(List<object> list) { for (Object listItem : list) System.out.println(listItem); }public static void printListItems(List<object> list) { for (Object listItem : list) System.out.println(listItem); } In … Read more

Wildcard in generics

Wildcard: In generics ‘?’ is known as wildcard and it represents an unknown type. Types of wildcard: Unbounded wildcard. Bounded wildcard. Upper bounded wildcard. Lower bounded wildcard. Unbounded wildcard.is used for list of unknown types using ‘?’(Type is not bounded). 2. Bounded wildcard: is used for unknown bounded types using ‘?’ with extends or super … Read more

ClassCastException at runtime test

Java generics runtime type checking : Let us see the ClassCastException at runtime test in generics with the below example. ClassCastException at run time test example: GenericsTest.java import java.util.ArrayList; import java.util.List;   /** * This class is used to show the * ClassCastException at runtime test. * @author w3schools */ public class GenericsTest { public … Read more

Compile time checking test

Let us see the compile time checking in java test with the below example. Generics compile time checking example: GenericsTest.java import java.util.ArrayList; import java.util.List;   /** * This class is used to show the compile time checking test. * @author w3schools */ public class GenericsTest { public static void main(String args[]){ //Arraylist without generics. List … Read more

Generics terms and naming convention

Generics terms and naming conventions makes the generics code easy to understand. Generics terms: Generic naming conventions: T : It represents type. E : It represents element. K – It represents keys. V – It represents values. N – It represents numbers.   Next Topic: Compile time checking test. Previous Topic: Generics in java.  

Junit test runner

Test runner is used for executing the test cases. Example: DivisionTestCase.java import com.w3schools.business.*; import static org.junit.Assert.*; import org.junit.Test;   /** * This is test case class for division method. * @author w3schools */ public class DivisionTestCase { //DivisionTest class objects DivisionTest divisionTest1 = new DivisionTest(10, 2); DivisionTest divisionTest2 = new DivisionTest(10, 0);   //Test case … Read more

JUnit parameterized test

The parameterized test is a new feature introduced in JUnit 4. It provides the facility to execute the same test case again and again with different values. Steps to create a parameterized test: 1. Test class have to be annotated with @RunWith(Parameterized.class) annotation. 2. Create a public static method with @Parameters annotation which returns a … Read more

JUnit suite test

The suite test refers to group a few unit test cases and run it together. The @RunWith and @Suite annotation are used to run the suite test. Example: TestSuite.java import org.junit.runner.RunWith; import org.junit.runners.Suite;   /** * This class is used as suite test class. * Both DivisionTestCase1 and DivisionTestCase2 * executes together after TestSuite is … Read more

JUnit time test

The time test is used to check that if a test case is completed within the specified time or not. JUnit terminate and mark it failed automatically if it takes more time than the specified milliseconds. We have to specify time in milliseconds in @Test(timeout = timeInMilliSeconds) action. Example: DivisionTestCase.java import com.w3schools.business.*; import static org.junit.Assert.*; … Read more

Junit ignore test

The @Ignore annotation is used to ignore test cases. The @Ignore annotation can be used with method or class. If it is used with the method then that method will be ignored by JUnit and will not execute and if it is used with the class then all methods of that class will be ignored … Read more