commit 21645084203ae74da9a57305d6cf01bf25c07a0c Author: iwakeh iwakeh@torproject.org Date: Fri Sep 30 11:56:35 2016 +0200
Added tests to point out areas for improvements with next refactoring. Improved coverage a little as aside-effect. --- .../bridgedescs/BridgeDescriptorParserTest.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/src/test/java/org/torproject/collector/bridgedescs/BridgeDescriptorParserTest.java b/src/test/java/org/torproject/collector/bridgedescs/BridgeDescriptorParserTest.java new file mode 100644 index 0000000..e89f512 --- /dev/null +++ b/src/test/java/org/torproject/collector/bridgedescs/BridgeDescriptorParserTest.java @@ -0,0 +1,48 @@ +/* Copyright 2016 The Tor Project + * See LICENSE for licensing information */ + +package org.torproject.collector.bridgedescs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.torproject.collector.conf.Configuration; + +import org.junit.Test; + +public class BridgeDescriptorParserTest { + + @Test(expected = IllegalArgumentException.class) + public void testNullArgForConstructor() throws Exception { + new BridgeDescriptorParser(null); + } + + @Test(expected = NullPointerException.class) + public void testNullData() throws Exception { + BridgeDescriptorParser bdp = new BridgeDescriptorParser( + new SanitizedBridgesWriter(new Configuration())); + bdp.parse(null, "", ""); + } + + @Test + /* Empty data is not passed down to the sanitized writer. + * This test passes when there is no exception. */ + public void testDataEmpty() throws Exception { + BridgeDescriptorParser bdp = new BridgeDescriptorParser( + new SanitizedBridgesWriter(new Configuration())); + bdp.parse(new byte[]{}, null, null); + } + + @Test(expected = NullPointerException.class) + /* The SanitizedBridgesWriter wasn't initialized sufficiently. + * Actually that should be corrected in SanitizedBridgesWriter + * at some point, but that's a bigger rewrite. */ + public void testMinimalData() throws Exception { + BridgeDescriptorParser bdp = new BridgeDescriptorParser( + new SanitizedBridgesWriter(new Configuration())); + bdp.parse(new byte[]{0}, "2010-10-10 10:10:10", null); + } + +}