### Question:
OAuthAdapter implements TokenAdapter<JsonValue> { public JsonValue fromToken(Token token) { if (token == null){ return null; } String data = blobUtils.getBlobAsString(token); if (data == null) { return null; } JsonValue r; try { r = new JsonValue(serialisation.deserialise(data, Map.class)); Set<String> keys = new HashSet<String>(r.keys()); for (String key : keys){ if (r.get(key).isList()) { List<String> x = r.get(key).asList(String.class); Set<String> set = new HashSet<String>(x); r.remove(key); r.add(key, set); } } } catch (IllegalStateException e) { return null; } return r; } @Inject  OAuthAdapter(TokenIdFactory tokenIdFactory, JSONSerialisation serialisation,
                        OAuthValues oAuthValues, TokenBlobUtils blobUtils); Token toToken(JsonValue request); JsonValue fromToken(Token token); static final String VALUE; }### Answer:
@Test public void shouldDeserialiseSerialisedToken() { String[] id = {"badger"}; List<String> list = new ArrayList<String>(Arrays.asList(id)); OAuthTokenField field = OAuthTokenField.ID; JSONSerialisation serialisation = new JSONSerialisation(new ObjectMapper()); OAuthAdapter adapter = generateOAuthAdapter(); Map<String, Object> values = new HashMap<String, Object>(); values.put(field.getOAuthField(), list); String serialisedObject = serialisation.serialise(values); Token token = new Token(id[0], TokenType.OAUTH); token.setBlob(serialisedObject.getBytes()); JsonValue result = adapter.fromToken(token); assertNotNull(result); assert(result.asMap().get(field.getOAuthField()).toString().contains(id[0])); }
@Test public void shouldNotDeserialiseATokenWhichDoesntContainAMap() { JSONSerialisation serialisation = new JSONSerialisation(new ObjectMapper()); OAuthAdapter adapter = generateOAuthAdapter(); Token token = new Token("", TokenType.OAUTH); token.setBlob(serialisation.serialise("badger").getBytes()); JsonValue fromToken = adapter.fromToken(token); assertThat(fromToken).isNull(); }