From c9081b41b54778795ffcc94a16ad1c8b7089db1b Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 2 Nov 2012 10:56:48 -0400 Subject: [PATCH] testing the big test: there and back again! --- .../java/com/redhat/trie/TestPathTree.java | 78 ++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/redhat/trie/TestPathTree.java b/src/test/java/com/redhat/trie/TestPathTree.java index e832c67..0599c9f 100644 --- a/src/test/java/com/redhat/trie/TestPathTree.java +++ b/src/test/java/com/redhat/trie/TestPathTree.java @@ -2,6 +2,7 @@ package com.redhat.trie; import java.util.List; import java.util.ArrayList; +import java.util.Collections; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; @@ -9,6 +10,7 @@ import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import org.junit.Test; @@ -23,14 +25,86 @@ public class TestPathTree { @Test public void testNew1() { PathTree pt = new PathTree(); + List contents = loadContents("contents.list"); + try { + pt = new PathTree(contents); + } catch (PayloadException ex) { + fail(ex.toString()); + } assertNotNull(pt); } + @Test + public void testNew2() { + PathTree pt = new PathTree(); + List contents = loadContents("contents.list"); + try { + pt.setContentSets(contents); + } catch (PayloadException ex) { + fail(ex.toString()); + } + assertNotNull(pt); + } + + @Test + public void testThereAndBackAgainCS() { + PathTree pt0 = new PathTree(); + PathTree pt1; + List contents0 = loadContents("contents.list"); + List contents1; + byte[] bytes; + + + try { + pt0.setContentSets(contents0); + } catch (PayloadException ex) { + fail(ex.toString()); + } + bytes = pt0.getPayload(); + assertNotNull(bytes); + printByteArray(bytes); + + pt1 = new PathTree(bytes); + contents1 = pt1.toList(); + + Collections.sort(contents0); + Collections.sort(contents1); + + for (String thisS : contents0) { + if (! contents1.contains(thisS)) { + System.out.println(thisS); + } + } + + //System.out.println(contents0.size()); + //System.out.println(contents1.size()); + assertEquals(contents0.size(), contents1.size()); + } + + + + // Helpers + // + private void printByteArray(byte[] bytes) { + int width = 30; + int counter = 0; + + for (byte b : bytes) { + System.out.format("%02X ", b); + counter++; + if (counter > width) { + counter = 0; + System.out.println(); + } + } + System.out.println(); + } + private InputStream resStream(String filename) { return getClass().getClassLoader().getResourceAsStream(filename); } - private List loadContents(String filename) throws IOException { + private List loadContents(String filename) { String content; List contentList = new ArrayList(); InputStream in = resStream(filename); @@ -41,7 +115,7 @@ public class TestPathTree { contentList.add(content); } } catch (IOException ex) { - throw ex; + fail(); } return contentList; }