Skip to content

Commit

Permalink
Fix import
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop committed Sep 23, 2024
1 parent 68980f3 commit 6a82a0d
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package org.radarbase.data;

import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import junit.framework.TestCase;
import org.apache.avro.specific.SpecificData;
import org.radarbase.topic.AvroTopic;
Expand All @@ -29,9 +25,22 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

import static org.junit.Assert.assertArrayEquals;

public class AvroDatumEncoderTest extends TestCase {
private static final Logger logger = LoggerFactory.getLogger(AvroDatumEncoderTest.class);

public static String byteArrayToHex(byte[] a) {
StringBuilder sb = new StringBuilder(a.length * 2);
for (byte b : a)
sb.append(String.format("%02x", b & 0xff));
return sb.toString();
}

public void testJson() throws IOException {
AvroDatumEncoder encoder = new AvroDatumEncoder(SpecificData.get(), false);
AvroTopic<ObservationKey, EmpaticaE4BloodVolumePulse> topic = new AvroTopic<>("keeeeys", ObservationKey.getClassSchema(), EmpaticaE4BloodVolumePulse.getClassSchema(), ObservationKey.class, EmpaticaE4BloodVolumePulse.class);
Expand All @@ -58,20 +67,13 @@ public void testBinary() throws IOException {
byte[] expectedKey = {2, 8, 116, 101, 115, 116, 2, 97, 2, 98};
System.out.println("key: 0x" + byteArrayToHex(key));
System.out.println("expected: 0x" + byteArrayToHex(expectedKey));
assertTrue(Arrays.equals(expectedKey, key));
assertArrayEquals(expectedKey, key);
byte[] value = valueEncoder.encode(new EmpaticaE4BloodVolumePulse(0d, 0d, 0f));
// 8 bytes, 8 bytes, 4 bytes, all zero
byte[] expectedValue = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
System.out.println("value: 0x" + byteArrayToHex(value));
System.out.println("expected: 0x" + byteArrayToHex(expectedValue));
assertTrue(Arrays.equals(expectedValue, value));
}

public static String byteArrayToHex(byte[] a) {
StringBuilder sb = new StringBuilder(a.length * 2);
for(byte b: a)
sb.append(String.format("%02x", b & 0xff));
return sb.toString();
assertArrayEquals(expectedValue, value);
}

public void testSize() throws IOException {
Expand Down

0 comments on commit 6a82a0d

Please sign in to comment.