Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Really add everything related to BSON symbols.
I forget to commit everything I've wanted last time, so here's an amendment for it. Also I didn't indicate I've updated the DefaultPredicate class (which I did), sooo ... that's a wrap!
- Loading branch information
1 parent
04ab8ec
commit 1644dce
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/com/github/kohanyirobert/ebson/DefaultSymbolReaderWriterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.kohanyirobert.ebson; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.primitives.Ints; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
public final class DefaultSymbolReaderWriterTest extends AbstractReaderWriterTest { | ||
|
||
private static final String SYMBOL_ALPHABET = "abcdefghijklmnopqrstuvwxyz"; | ||
private static final int MAX_SYMBOL_LENGTH = 1024; | ||
private static final ThreadLocal<ByteBuffer> RANDOM_SYMBOL = new ThreadLocal<ByteBuffer>() { | ||
|
||
@Override | ||
protected ByteBuffer initialValue() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < BsonRandom.nextInt(MAX_SYMBOL_LENGTH); i++) | ||
sb.append(SYMBOL_ALPHABET.charAt(BsonRandom.nextInt(SYMBOL_ALPHABET.length()))); | ||
ByteBuffer symbol = ByteBuffer.allocate(Ints.BYTES + sb.length() + 1) | ||
.order(ByteOrder.LITTLE_ENDIAN) | ||
.putInt(sb.length() + 1) | ||
.put(sb.toString().getBytes(Charsets.UTF_8)) | ||
.put(BsonBytes.EOO); | ||
symbol.flip(); | ||
return symbol; | ||
} | ||
}; | ||
|
||
public DefaultSymbolReaderWriterTest() { | ||
super(DefaultReader.SYMBOL, DefaultWriter.SYMBOL); | ||
} | ||
|
||
@Test | ||
public void randomSymbol() { | ||
assertEquals(writeTo(new BasicSymbol(RANDOM_SYMBOL.get())), readFrom()); | ||
} | ||
} |