Some of our test data needs to be transformed from its original type to something else. For example, we might need to convert a String to a numeric value, or vice versa. Or we might need to generate date values in a certain format. Examples for all of these can be found below.
Easily compare a list of Strings with the contents of a file
Context: you need to check that the values you have in a List of Strings are the same as the contents of a file. An element in the List will correspond to an entire line from the file. How can you achieve this easily?
Removing all digits, non-digits, whitespaces (from Strings) and other usages of replaceAll
Some tasks will require you to replace all occurrences of certain Strings from other Strings with something else, based on a pattern. Or remove all those occurrences. For example, maybe you want to only keep the numeric characters of a String. Or remove all numeric characters. Or maybe remove all white spaces. For this, the… Read More
Extracting substrings with StringUtils from the Apache library
Following on from some of my earlier posts, where I described some of the useful utils from the apache.commons.lang3 library (like that very nice RandomStringUtils class), this time I will focus a bit on the StringUtils class. As the name suggests, it provides developers and testers an easy way to deal with certain String related… Read More
Useful: generating random strings with RandomStringUtils
When writing tests that require the generation of random strings, a very useful class can come in handy, namely RandomStringUtils from the Apache Commons Langs utilities library. It can be used for generating string that contain only letters, only numbers, both, these and other characters.