JUnit4 Annotations and Ant Workaround

Posted on 2011/02/10

I usually use Maven for Java based projects, so my ant skills are a little rusty. Recently It was whipping up some JUnit negative test cases for someone else’s project that was a mess of ant build files (ugh). I decided to use some of the nifty annotation features found in JUnit 4.8.2 ( for rules and expected exception behavior). Annotations are great for addressing defects in the Java language, and help encapsulation by associating behavior directly with a class. But I digress… Anyway All the tests to check exceptions were thrown under negative test conditions looked good inside of Eclipse, but when I ran the ant test script from the command line, none of tests were being run encfprcomg the annotations, even though the JUnit jar was in the ant classpath! A little research showed that ant’s JUnit test runner doesn’t support annotations. The solution was to modify the suite() method of the AllTests class to wrap the classes under test in a JUnit4TestAdapter, i.e. something like this:

@RunWith(JUnit4.class)
public class AllTests extends TestSuite {
    
    public static junit.framework.Test suite() {
            return new JUnit4TestAdapter(TestSomething.class);
    }
}

XML Encoding, UTF-8 / UTF-16 Confusion

Posted on 2011/02/03

Here’s a frustrating little problem I found when a service I deal with (we’ll call it SystemA for “Awesome”) suddenly changed character encoding… My app was suddenly getting parse exceptions for XML messages after an upgrade to SystemA was deployed to a test environment. A peak at my logs showed the xml response looked funky, with extra spaces all throught it… no wonder my XML API went blooey:

< ? x m l v e r s i o n = ” 1 . 0 ” e n c o d i n g = ” U T F – 8 ” ? >

I blinked a little, then tried a copy paste from the log file to put into a bug note and got this little gem from textpad:

Cannot cut, copy, or drag and dtop text containing null (code = 0) characters.

Cannot cut, copy, or drag and dtop text containing null (code = 0) characters.

Sweet!

I opened the file up in a Hex Editor, and low and behold there were extra nulls chars all through it. Even though the xml header specified UTF-8, it looked like it was actually encoded in UTF-16.

Continue Reading →

Fix for ipad activation error, updating from expired 4.2 beta to newest beta

Posted on 2010/10/30
Shan's iPad

Shan\’s iPad

Yesterday I turned on my iPad and got the connect to itunes logo…I was a little freaked, but plugged her in to my workstation. I got a message that the ios 4.2 beta was expired and I need to update (yes, I AM a member of the Apple Developer Program).

I download the latest ios sdk, and tried to update via iTunes 10 using the iPad1,14.28C5101c ipsw . The update failed and I went into restore mode. Forgetting that downgrades are not supported, I tried to the default restore (3.2. something). Now I got an error 1015 on update… So next I restored the same ispw using iTunes again. Next I got an activation error stating the device was not registered in the developer program and to register the deviceid via the developers provision portal. I tried to go back to restore/DFU mode using the normal means (home & sleep button,etc), but it would not re-enter restore mode….it would go straight to the connect to iTunes screen. Once I connected back to iTunes, I got the same activation error again, with no way to get my deviceid from iTunes!

Continue Reading →