Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean containsKey(String key)
*/
public boolean containsKey(String key, Charset charset)
{
return meta.containsKey(BinaryValue.unsafeCreate(key.getBytes()));
return meta.containsKey(BinaryValue.unsafeCreate(key.getBytes(charset)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.basho.riak.client.core.query.UserMetadata;

import com.basho.riak.client.core.util.BinaryValue;
import org.junit.Test;

import java.nio.charset.Charset;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class RiakUserMetadataTest
{
final Charset utf16 = Charset.forName("UTF-16");
final String oddKey = "\uD834\uDD1E\uD835\uDD65";
final String oddValue = "\uD835\uDFF6\uD840\uDC8A";
final BinaryValue oddKeyBV = BinaryValue.create(oddKey, utf16);
final BinaryValue oddValueBV = BinaryValue.create(oddValue, utf16);

@Test
public void getSetMetadata_string_altCharset()
{
RiakUserMetadata md = new RiakUserMetadata();
md.put(oddKey, oddValue, utf16);
final String gotValue = md.get(oddKey, utf16);

assertEquals(oddValue, gotValue);
assertNotEquals(gotValue, md.get(oddKey));
}

@Test
public void getSetMetadata_binaryValue_altCharset()
{
RiakUserMetadata md = new RiakUserMetadata();
md.put(oddKeyBV, oddValueBV);
final BinaryValue gotValue = md.get(oddKeyBV);

assertEquals(oddValueBV, gotValue);
assertNotEquals(gotValue, md.get(oddKey));
}

@Test
public void getSetMetadata_mixedInterfaces_altCharset()
{
RiakUserMetadata md = new RiakUserMetadata();
md.put(oddKeyBV, oddValueBV);

final String gotValue = md.get(oddKey, utf16);

assertEquals(oddValue, gotValue);
}
}