zaubersoftware/gnip4j — Issue #8: Bug in  JSONDeserializationTest#testNPE()
Author: miguno
Created: 2011-12-01 12:45:51+00:00
State: open

The test ``testNPE()`` in ``com.zaubersoftware.gnip4j.http.JSONDeserializationTest`` fails on trunk because the private function ``removeTimeZoneFields()`` is using an incorrect regex for parsing ``postedTime`` attributes.

The bug is triggered in this line:

```
assertEquals(removeTimeZoneFields(IOUtils.toString(expectedIs)), removeTimeZoneFields(ww.toString()));
```

The test data is in ``payload-twitter-entities.js`` (for ``expectedIs``) and in ``payload-twitter-entities.xml`` (for ``ww``).

However, the ``postedTime`` values in ``expectedIs`` and ``ww`` are different:

```

[...] postedTime="2008-05-07T16:27:40.000+02:00">

[...] postedTime="2008-05-07T11:27:40.000-03:00">
```

As you can see, the first string has ``+02:00`` (note the ``+`` character). I'm not sure how the "+02:00" got there in the first place; I could find it in neither the .js nor in the .xml file. Maybe it is being (incorrectly) deduced from my own local time zone (which is CET, i.e. UTC+1) ?

What happens is that the regex in ``removeTimeZoneFields()`` will remove the ``-03:00`` postedTime attribute, but it will fail to match on the ``+`` -- the in ``+02:00`` and therefore not remove this postedTime attribute. This causes the unit test to fail.

I can reproduce this bug by running the build, e.g. via ``mvn test`` or ``mvn install`` in the top-level directory. I tested this on Ubuntu 11.10 and Maven 3.

The following change fixes the problem:

In ``com.zaubersoftware.gnip4j.http.JSONDeserializationTest``, replace

```
return input.replaceAll("postedTime=\"[\\d-T:\\.]*\"", "");
```

With

```
return input.replaceAll("postedTime=\"[\\d-\\+T:\\.]*\"", "");
```

I'll also send a pull request if you're happy with this patch.