In this post under Apache Commons IO, I will show with example how to write String data to an output stream. The Apache Commons IO library, provides a overloaded static method “write” under “IOUtils” class. We can use this method to write String data to an output stream. Its just a one line of code.…… Continue reading Writing String data to an output stream
Category: Uncategorized
BiFunction Example
In this post, I will show how to use BiFunction functional interface with an example. BiFunction functional interface is similar to Function functional interface. It takes an input and produces an output. The difference lies in the number of inputs taken by the BiFunction functional interface. Function functional interface takes one input and produced one…… Continue reading BiFunction Example
Unit testing method exceptions
Sometime we have to test whether a method throws proper and required exceptions or not. One way of testing is placing the method call (to be tested) inside a try catch block, as shown below try { class2.method1(); fail(“Should have thrown exception”); } catch(IllegalArgumentException excep) { } catch(Exception excep) { fail(“Should have thrown IllegalArgumentException exception”);…… Continue reading Unit testing method exceptions
Setting timeout for test methods
Junit offers us the option to set timeout for test methods. If a test methods doesnt complete within specified time limit, an exception is thrown failing the test case. The use case scenario where this feature can be used is for example testing the performance of a method. The below code shows you how to…… Continue reading Setting timeout for test methods
Making JUnit ignore test methods
If we want JUnit to ignore certain test methods we can do that by using the @Ignore annotation applied on the methods that has to be ignored. The below test class tests a functionality of a calculator CalculatorTest package Package1; import static org.junit.Assert.assertEquals; import org.junit.Ignore; import org.junit.Test; @Ignore public class CalculatorTest { @Test public void…… Continue reading Making JUnit ignore test methods