Permalink
Browse files

Refactor setup and teardown

  • Loading branch information...
1 parent ea4a8bd commit dbf8659ac142c978702ac871add2dcfcc2d852db @samstokes samstokes committed May 23, 2012
Showing with 23 additions and 28 deletions.
  1. +23 −28 src/test/java/com/rapportive/jawbone/JawboneTest.java
@@ -8,9 +8,7 @@
import static org.junit.Assert.*;
-import org.junit.After;
import org.junit.BeforeClass;
-import org.junit.Before;
import org.junit.Test;
import com.sun.jna.Native;
@@ -22,8 +20,6 @@
public class JawboneTest {
private static JawboneBinding binding;
- private PointerByReference jawbonePtr = new PointerByReference();
- private Pointer jawbone;
private static byte[] wbxml;
@@ -34,38 +30,37 @@ public static void setUpBeforeClass() throws Exception {
binding = JawboneBinding.INSTANCE;
}
- @Before
- public void setUp() throws Exception {
+ @Test
+ public void test() throws Exception {
+ PointerByReference jawbonePtr = new PointerByReference();
+ Pointer jawbone = null;
+
int ret = binding.wbxml_conv_wbxml2xml_create(jawbonePtr);
assertEquals("wbxml_conv_wbxml2xml_create failed", 0, ret);
jawbone = jawbonePtr.getValue();
- }
- @Test
- public void test() throws Exception {
- binding.wbxml_conv_wbxml2xml_set_gen_type(jawbone, 2); /* WBXML_GEN_XML_CANONICAL */
- binding.wbxml_conv_wbxml2xml_set_language(jawbone, 2402); /* WBXML_LANG_ACTIVESYNC */
- binding.wbxml_conv_wbxml2xml_set_charset(jawbone, 0); /* WBXML_CHARSET_UNKNOWN */
- binding.wbxml_conv_wbxml2xml_set_indent(jawbone, 4); /* 4-space indent */
- binding.wbxml_conv_wbxml2xml_enable_preserve_whitespaces(jawbone);
-
- PointerByReference xmlPtr = new PointerByReference();
- LongByReference xmlLength = new LongByReference();
- int ret = binding.wbxml_conv_wbxml2xml_run(jawbone, wbxml, wbxml.length, xmlPtr, xmlLength);
+ try {
+ binding.wbxml_conv_wbxml2xml_set_gen_type(jawbone, 2); /* WBXML_GEN_XML_CANONICAL */
+ binding.wbxml_conv_wbxml2xml_set_language(jawbone, 2402); /* WBXML_LANG_ACTIVESYNC */
+ binding.wbxml_conv_wbxml2xml_set_charset(jawbone, 0); /* WBXML_CHARSET_UNKNOWN */
+ binding.wbxml_conv_wbxml2xml_set_indent(jawbone, 4); /* 4-space indent */
+ binding.wbxml_conv_wbxml2xml_enable_preserve_whitespaces(jawbone);
- assertEquals("wbxml_conv_wbxml2xml_run failed", 0, ret);
- assertTrue("returned no XML", xmlLength.getValue() > 0);
+ PointerByReference xmlPtr = new PointerByReference();
+ LongByReference xmlLength = new LongByReference();
+ ret = binding.wbxml_conv_wbxml2xml_run(jawbone, wbxml, wbxml.length, xmlPtr, xmlLength);
- byte[] xmlBytes = xmlPtr.getValue().getByteArray(0L, (int) xmlLength.getValue());
- Native.free(Pointer.nativeValue(xmlPtr.getValue()));
+ assertEquals("wbxml_conv_wbxml2xml_run failed", 0, ret);
+ assertTrue("returned no XML", xmlLength.getValue() > 0);
- assertEquals("returned b0rked bytes", xmlLength.getValue(), xmlBytes.length);
- }
+ byte[] xmlBytes = xmlPtr.getValue().getByteArray(0L, (int) xmlLength.getValue());
+ Native.free(Pointer.nativeValue(xmlPtr.getValue()));
- @After
- public void tearDown() throws Exception {
- if (jawbone != null) {
- binding.wbxml_conv_wbxml2xml_destroy(jawbone);
+ assertEquals("returned b0rked bytes", xmlLength.getValue(), xmlBytes.length);
+ } finally {
+ if (jawbone != null) {
+ binding.wbxml_conv_wbxml2xml_destroy(jawbone);
+ }
}
}

0 comments on commit dbf8659

Please sign in to comment.