From e13c27471e04afee403b8468a9ccb846d729a1d0 Mon Sep 17 00:00:00 2001 From: Rohan Chakravarthy Date: Tue, 19 Apr 2016 19:56:04 -0400 Subject: [PATCH] Added tests for NumberParser --- .../rome/io/impl/NumberParserTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 rome/src/test/java/com/rometools/rome/io/impl/NumberParserTest.java diff --git a/rome/src/test/java/com/rometools/rome/io/impl/NumberParserTest.java b/rome/src/test/java/com/rometools/rome/io/impl/NumberParserTest.java new file mode 100644 index 0000000..ebb93ea --- /dev/null +++ b/rome/src/test/java/com/rometools/rome/io/impl/NumberParserTest.java @@ -0,0 +1,72 @@ +package com.rometools.rome.io.impl; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + + +public class NumberParserTest { + + @Test + public void testLongParseFailure() { + Long num = NumberParser.parseLong("Non Long"); + assertNull(num); + } + + @Test + public void testLongParseSuccess() { + Long num = NumberParser.parseLong("1"); + assertEquals(new Long(1L), num); + } + + @Test + public void testLongParseDefaultSuccess() { + long num = NumberParser.parseLong("Non Long", 1L); + assertEquals(1L, num); + } + + @Test + public void testLongParseNonDefaultSuccess() { + long num = NumberParser.parseLong("0", 1L); + assertEquals(0L, num); + } + + @Test + public void testIntParseFailure() { + Integer num = NumberParser.parseInt("Non Int"); + assertNull(num); + } + + @Test + public void testIntParseSuccess() { + Integer num = NumberParser.parseInt("1"); + assertEquals(new Integer(1), num); + } + + @Test + public void testFloatParseFailure() { + Float num = NumberParser.parseFloat("Non Float"); + assertNull(num); + } + + @Test + public void testFloatParseSuccess() { + Float num = NumberParser.parseFloat("1.0"); + assertEquals(new Float(1.0f), num); + } + + @Test + public void testFloatParseDefaultSuccess() { + float num = NumberParser.parseFloat("Non Float", 1.0f); + assertEquals(1.0f, num, 0); + } + + @Test + public void testFloatParseNonDefaultSuccess() { + float num = NumberParser.parseFloat("0.0", 1.0f); + assertEquals(0.0f, num, 0); + } + +}