Skip to content

Commit

Permalink
Use msg-simple for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fge committed Jun 25, 2013
1 parent 85cc6d7 commit db087f9
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ target
.idea
build
.gradle

out
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ dependencies {
compile(group: "com.fasterxml.jackson.core", name: "jackson-databind",
version: "2.2.2");
compile(group: "com.google.guava", name: "guava", version: "14.0.1");
compile(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1") {
compile(group: "com.github.fge", name: "msg-simple", version: "0.7");
compile(group: "com.google.code.findbugs", name: "jsr305",
version: "2.0.1") {
transitive = true
};
testCompile(group: "org.testng", name: "testng", version: "6.8") {
Expand Down
5 changes: 3 additions & 2 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ project.ext {
*/

project.ext {
// Uncomment and fill the array below as appropriate.
// serviceClasses = [];
serviceClasses = [
"com.github.fge.msgsimple.serviceloader.MessageBundleProvider"
];
};

project.ext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.MissingNode;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -144,7 +143,7 @@ public JsonPointer append(final int index)
*/
public JsonPointer append(final JsonPointer other)
{
Preconditions.checkNotNull(other, BUNDLE.getString("nullInput"));
BUNDLE.checkNotNull(other, "nullInput");
final List<TokenResolver<JsonNode>> list
= Lists.newArrayList(tokenResolvers);
list.addAll(other.tokenResolvers);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.fge.jackson.jsonpointer;

import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.bundle.PropertiesBundle;
import com.github.fge.msgsimple.serviceloader.MessageBundleProvider;

public final class JsonPointerMessages
implements MessageBundleProvider
{
@Override
public MessageBundle getBundle()
{
return PropertiesBundle.forPath("com/github/fge/jackson/jsonpointer");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package com.github.fge.jackson.jsonpointer;

import com.google.common.base.Preconditions;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.serviceloader.MessageBundleFactory;
import com.google.common.collect.ImmutableList;

import javax.annotation.concurrent.Immutable;
import java.util.List;
import java.util.ResourceBundle;


/**
Expand All @@ -42,8 +42,8 @@
@Immutable
public final class ReferenceToken
{
private static final ResourceBundle BUNDLE
= ResourceBundle.getBundle("jsonpointer");
private static final MessageBundle BUNDLE
= MessageBundleFactory.getBundle(JsonPointerMessages.class);
/**
* The escape character in a cooked token
*/
Expand Down Expand Up @@ -99,7 +99,7 @@ private ReferenceToken(final String cooked, final String raw)
public static ReferenceToken fromCooked(final String cooked)
throws JsonPointerException
{
Preconditions.checkNotNull(cooked, BUNDLE.getString("nullInput"));
BUNDLE.checkNotNull(cooked, "nullInput");
return new ReferenceToken(cooked, asRaw(cooked));
}

Expand All @@ -112,7 +112,7 @@ public static ReferenceToken fromCooked(final String cooked)
*/
public static ReferenceToken fromRaw(final String raw)
{
Preconditions.checkNotNull(raw, BUNDLE.getString("nullInput"));
BUNDLE.checkNotNull(raw, "nullInput");
return new ReferenceToken(asCooked(raw), raw);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ private static String asRaw(final String cooked)
}

if (inEscape)
throw new JsonPointerException(BUNDLE.getString("emptyEscape"));
throw new JsonPointerException(BUNDLE.getMessage("emptyEscape"));

return raw.toString();
}
Expand All @@ -212,7 +212,7 @@ private static void appendEscaped(final StringBuilder sb, final char c)
{
final int index = ENCODED.indexOf(c);
if (index == -1)
throw new JsonPointerException(BUNDLE.getString("illegalEscape"));
throw new JsonPointerException(BUNDLE.getMessage("illegalEscape"));

sb.append(DECODED.get(index));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.MissingNode;
import com.google.common.base.Preconditions;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.serviceloader.MessageBundleFactory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import javax.annotation.concurrent.ThreadSafe;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;

/**
* A pointer into a {@link TreeNode}
Expand Down Expand Up @@ -57,8 +57,8 @@
public abstract class TreePointer<T extends TreeNode>
implements Iterable<TokenResolver<T>>
{
protected static final ResourceBundle BUNDLE
= ResourceBundle.getBundle("jsonpointer");
protected static final MessageBundle BUNDLE
= MessageBundleFactory.getBundle(JsonPointerMessages.class);
/**
* The reference token separator
*/
Expand Down Expand Up @@ -114,8 +114,7 @@ protected TreePointer(final List<TokenResolver<T>> tokenResolvers)
protected static List<ReferenceToken> tokensFromInput(final String input)
throws JsonPointerException
{
String s = Preconditions.checkNotNull(input,
BUNDLE.getString("nullInput"));
String s = BUNDLE.checkNotNull(input, "nullInput");
final List<ReferenceToken> ret = Lists.newArrayList();
String cooked;
int index;
Expand All @@ -124,7 +123,7 @@ protected static List<ReferenceToken> tokensFromInput(final String input)
while (!s.isEmpty()) {
c = s.charAt(0);
if (c != SLASH)
throw new JsonPointerException(BUNDLE.getString("notSlash"));
throw new JsonPointerException(BUNDLE.getMessage("notSlash"));
s = s.substring(1);
index = s.indexOf(SLASH);
cooked = index == -1 ? s : s.substring(0, index);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nullInput = input cannot be null
emptyEscape = bad escape sequence: '~' not followed by any token
illegalEscape = bad escape seqeunce: '~' not followed by a valid token
notSlash = illegal pointer: expected a slash to separate tokens
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jackson.NodeType;
import com.github.fge.jackson.SampleNodeProvider;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.serviceloader.MessageBundleFactory;
import com.google.common.collect.Lists;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand All @@ -33,14 +35,13 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import static org.testng.Assert.*;

public final class JsonPointerTest
{
private static final ResourceBundle BUNDLE
= ResourceBundle.getBundle("jsonpointer");
private static final MessageBundle BUNDLE
= MessageBundleFactory.getBundle(JsonPointerMessages.class);

private final JsonNode testData;
private final JsonNode document;
Expand All @@ -60,7 +61,7 @@ public void cannotAppendNullPointer()
JsonPointer.empty().append(foo);
fail("No exception thrown!!");
} catch (NullPointerException e) {
assertEquals(e.getMessage(), BUNDLE.getString("nullInput"));
assertEquals(e.getMessage(), BUNDLE.getMessage("nullInput"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@

package com.github.fge.jackson.jsonpointer;

import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.serviceloader.MessageBundleFactory;
import com.google.common.collect.ImmutableList;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Iterator;
import java.util.ResourceBundle;

import static org.testng.Assert.*;

public final class ReferenceTokenTest
{
private static final ResourceBundle BUNDLE
= ResourceBundle.getBundle("jsonpointer");
private static final MessageBundle BUNDLE
= MessageBundleFactory.getBundle(JsonPointerMessages.class);

@Test
public void nullCookedRaisesError()
Expand All @@ -39,7 +40,7 @@ public void nullCookedRaisesError()
ReferenceToken.fromCooked(null);
fail("No exception thrown!!");
} catch (NullPointerException e) {
assertEquals(e.getMessage(), BUNDLE.getString("nullInput"));
assertEquals(e.getMessage(), BUNDLE.getMessage("nullInput"));
}
}
@Test
Expand All @@ -49,7 +50,7 @@ public void nullRawRaisesError()
ReferenceToken.fromRaw(null);
fail("No exception thrown!!");
} catch (NullPointerException e) {
assertEquals(e.getMessage(), BUNDLE.getString("nullInput"));
assertEquals(e.getMessage(), BUNDLE.getMessage("nullInput"));
}
}

Expand All @@ -60,7 +61,7 @@ public void emptyEscapeRaisesTheAppropriateException()
ReferenceToken.fromCooked("whatever~");
fail("No exception thrown!!");
} catch (JsonPointerException e) {
assertEquals(e.getMessage(), BUNDLE.getString("emptyEscape"));
assertEquals(e.getMessage(), BUNDLE.getMessage("emptyEscape"));
}
}

Expand All @@ -71,7 +72,7 @@ public void illegalEscapeRaisesTheAppropriateException()
ReferenceToken.fromCooked("~a");
fail("No exception thrown!!");
} catch (JsonPointerException e) {
assertEquals(e.getMessage(), BUNDLE.getString("illegalEscape"));
assertEquals(e.getMessage(), BUNDLE.getMessage("illegalEscape"));
}
}

Expand Down

0 comments on commit db087f9

Please sign in to comment.