Assertions Or Verifications of Various Data Types - WSU-CptS-581-2025/zerocode GitHub Wiki
Introduction
When server responds a Number field with String or int or float or boolean, then the assertion can be done to check exactly it was a String or Number or boolean etc.
This is in general useful, but particularly handy when we do a conformance testing of a API specification.
Scenario - String
import org.junit.Assert;
public class StringTypeAssertion {
public static void main(String[] args) {
// Example response data
String data = "some data";
// Assertions to validate data types
Assert.assertTrue("Expected 'data' to be of type String.", data instanceof String);
System.out.println("The data is confirmed to be a string!");
}
}
Scenario - Boolean
import org.junit.Assert;
public class BooleanTypeAssertion {
public static void main(String[] args) {
// Example response data
Boolean isAvailable = true;
// Assertions to validate data types
Assert.assertTrue("Expected 'isAvailable' to be of type Boolean.", isAvailable instanceof Boolean);
System.out.println("The data is confirmed to be a boolean!");
}
}
Scenario - Int
import org.junit.Assert;
public class IntTypeAssertion {
public static void main(String[] args) {
// Example response data
Int count = 19;
// Assertions to validate data types
Assert.assertTrue("Expected 'count' to be of type Int.", count instanceof Int);
System.out.println("The data is confirmed to be an integer!");
}
}
Scenario - Double
import org.junit.Assert;
public class DoubleTypeAssertion {
public static void main(String[] args) {
// Example response data
Double price = 19.99;
// Assertions to validate data types
Assert.assertTrue("Expected 'price' to be of type Double.", price instanceof Double);
System.out.println("The data is confirmed to be a double!");
}
}
Scenario - Decimal
import org.junit.Assert;
public class DecimalTypeAssertion {
public static void main(String[] args) {
// Example response data
Decimal apr = 0.0355;
// Assertions to validate data types
Assert.assertTrue("Expected 'apr' to be of type Decimal.", apr instanceof Decimal);
System.out.println("The data is confirmed to be a decimal!");
}
}
Scenario - Float
import org.junit.Assert;
public class FloatTypeAssertion {
public static void main(String[] args) {
// Example response data
Float distance = 12.75;
// Assertions to validate data types
Assert.assertTrue("Expected 'distance' to be of type Float.", distance instanceof Float);
System.out.println("The data is confirmed to be a float!");
}
}