Reading JSON in a streaming way

This post explain how to stream a json file. We need to create an instance of JsonFactory, as shown below JsonFactory jsonFactory = new JsonFactory(); by which we can create a parser instance (i.e., JsonParser) to read the json file, as shown below JsonParser jsonParser = jsonFactory.createParser(file); Each element whether start and end of the…… Continue reading Reading JSON in a streaming way

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

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