### Question:
HeaderUtils { public static void addHeader(Headers headers, String key, Object value) { notNull(headers, () -> "headers may not be null"); if (value instanceof Instant) { headers.add(key, toBytes((Number) ((Instant) value).toEpochMilli())); } else if (value instanceof Number) { headers.add(key, toBytes((Number) value)); } else if (value instanceof String) { headers.add(key, ((String) value).getBytes(UTF_8)); } else if (value == null) { headers.add(key, null); } else { headers.add(key, value.toString().getBytes(UTF_8)); } } private  HeaderUtils(); static Long asLong(byte[] value); static Long valueAsLong(Headers headers, String key); static String asString(byte[] value); static String valueAsString(Headers headers, String key); static String valueAsString(Headers headers, String key, String defaultValue); @SuppressWarnings("ConstantConditions") // Null check performed by `Assert.isTrue` static byte[] value(Headers headers, String key); static byte[] toBytes(Number value); static void addHeader(Headers headers, String key, Object value); static Set<String> keys(Headers headers); static String generateMetadataKey(String key); @SuppressWarnings("ConstantConditions") // Null check performed by `Assert.isTrue` call static String extractKey(String metaDataKey); static Map<String, Object> extractAxonMetadata(Headers headers); static Headers toHeaders(EventMessage<?> eventMessage,
                                    SerializedObject<byte[]> serializedObject,
                                    BiFunction<String, Object, RecordHeader> headerValueMapper); static BiFunction<String, Object, RecordHeader> byteMapper();  }### Answer:
@Test public void testWritingNonNegativeValuesShouldBeWrittenAsNonNegativeValues() { RecordHeaders target = new RecordHeaders(); short expectedShort = 1; int expectedInt = 200; long expectedLong = 300L; float expectedFloat = 300.f; double expectedDouble = 0.000; addHeader(target, "short", expectedShort); assertThat(shortValue(target)).isEqualTo(expectedShort); addHeader(target, "int", expectedInt); assertThat(intValue(target)).isEqualTo(expectedInt); addHeader(target, "long", expectedLong); assertThat(longValue(target)).isEqualTo(expectedLong); addHeader(target, "float", expectedFloat); assertThat(floatValue(target)).isEqualTo(expectedFloat); addHeader(target, "double", expectedDouble); assertThat(doubleValue(target)).isEqualTo(expectedDouble); }
@Test public void testWritingNegativeValuesShouldBeWrittenAsNegativeValues() { RecordHeaders target = new RecordHeaders(); short expectedShort = -123; int expectedInt = -1_234_567_8; long expectedLong = -1_234_567_89_0L; float expectedFloat = -1_234_567_89_0.0f; double expectedDouble = -1_234_567_89_0.987654321; addHeader(target, "short", expectedShort); assertThat(shortValue(target)).isEqualTo(expectedShort); addHeader(target, "int", expectedInt); assertThat(intValue(target)).isEqualTo(expectedInt); addHeader(target, "long", expectedLong); assertThat(longValue(target)).isEqualTo(expectedLong); addHeader(target, "float", expectedFloat); assertThat(floatValue(target)).isEqualTo(expectedFloat); addHeader(target, "double", expectedDouble); assertThat(doubleValue(target)).isEqualTo(expectedDouble); }
@Test(expected = IllegalArgumentException.class) public void testWritingNonPrimitiveJavaValueShouldThrowAnException() { addHeader(new RecordHeaders(), "short", BigInteger.ZERO); }