package se.fnord.katydid;

import se.fnord.katydid.internal.TestingContext;

import java.nio.ByteBuffer;

public class DataAsserts {

	public static void assertNext(DataTester dataTester, ByteBuffer bb) {
		int m = dataTester.passCount();
		TestingContext tc = new TestingContext(bb);
		int pos = bb.position();
		for (int i = 0; i < m; i++) {
			bb.position(pos);
			dataTester.compareTo(i, tc);
		}
	}

	public static void assertExact(DataTester dataTester, ByteBuffer bb) {
		ByteBuffer bb2 = bb.slice();
		assertNext(dataTester, bb2);
		if (bb2.hasRemaining())
			throw new AssertionError(String.format("Expected %d bytes, was %d bytes", dataTester.length(), bb.remaining()));
	}

	public static void assertExact(DataTester dataTester, byte[] bytes) {
		assertExact(dataTester, ByteBuffer.wrap(bytes));
	}
}

@@ -802,11 +802,211 @@
 es));%0A%09%7D
+%0A%0A%09public static ByteBuffer asBuffer(DataTester dataTester) %7B%0A%09%09int length = dataTester.length();%0A%09%09ByteBuffer bb = ByteBuffer.allocate(length);%0A%09%09dataTester.toBuffer(bb);%0A%09%09bb.flip();%0A%09%09return bb;%0A%09%7D
 %0A%7D%0A

Add asBuffer() for converting a DataTester to a byte buffer