### Question:
Adapter { @VisibleForTesting static <T> Model.KeyValue toKeyValue(AttributeKey<T> key, T value) { Model.KeyValue.Builder builder = Model.KeyValue.newBuilder(); builder.setKey(key.getKey()); switch (key.getType()) { case STRING: builder.setVStr((String) value); builder.setVType(Model.ValueType.STRING); break; case LONG: builder.setVInt64((long) value); builder.setVType(Model.ValueType.INT64); break; case BOOLEAN: builder.setVBool((boolean) value); builder.setVType(Model.ValueType.BOOL); break; case DOUBLE: builder.setVFloat64((double) value); builder.setVType(Model.ValueType.FLOAT64); break; case STRING_ARRAY: case LONG_ARRAY: case BOOLEAN_ARRAY: case DOUBLE_ARRAY: builder.setVStr(new Gson().toJson(value)); builder.setVType(Model.ValueType.STRING); break; } return builder.build(); } private  Adapter();   }### Answer:
@Test void testKeyValue() { Model.KeyValue kvB = Adapter.toKeyValue(booleanKey("valueB"), true); Model.KeyValue kvD = Adapter.toKeyValue(doubleKey("valueD"), 1.); Model.KeyValue kvI = Adapter.toKeyValue(longKey("valueI"), 2L); Model.KeyValue kvS = Adapter.toKeyValue(stringKey("valueS"), "foobar"); Model.KeyValue kvArrayB = Adapter.toKeyValue(booleanArrayKey("valueArrayB"), Arrays.asList(true, false)); Model.KeyValue kvArrayD = Adapter.toKeyValue(doubleArrayKey("valueArrayD"), Arrays.asList(1.2345, 6.789)); Model.KeyValue kvArrayI = Adapter.toKeyValue(longArrayKey("valueArrayI"), Arrays.asList(12345L, 67890L)); Model.KeyValue kvArrayS = Adapter.toKeyValue(stringArrayKey("valueArrayS"), Arrays.asList("foobar", "barfoo")); assertTrue(kvB.getVBool()); assertEquals(Model.ValueType.BOOL, kvB.getVType()); assertEquals(1., kvD.getVFloat64(), 0); assertEquals(Model.ValueType.FLOAT64, kvD.getVType()); assertEquals(2, kvI.getVInt64()); assertEquals(Model.ValueType.INT64, kvI.getVType()); assertEquals("foobar", kvS.getVStr()); assertEquals("foobar", kvS.getVStrBytes().toStringUtf8()); assertEquals(Model.ValueType.STRING, kvS.getVType()); assertEquals("[true,false]", kvArrayB.getVStr()); assertEquals("[true,false]", kvArrayB.getVStrBytes().toStringUtf8()); assertEquals(Model.ValueType.STRING, kvArrayB.getVType()); assertEquals("[1.2345,6.789]", kvArrayD.getVStr()); assertEquals("[1.2345,6.789]", kvArrayD.getVStrBytes().toStringUtf8()); assertEquals(Model.ValueType.STRING, kvArrayD.getVType()); assertEquals("[12345,67890]", kvArrayI.getVStr()); assertEquals("[12345,67890]", kvArrayI.getVStrBytes().toStringUtf8()); assertEquals(Model.ValueType.STRING, kvArrayI.getVType()); assertEquals("[\"foobar\",\"barfoo\"]", kvArrayS.getVStr()); assertEquals("[\"foobar\",\"barfoo\"]", kvArrayS.getVStrBytes().toStringUtf8()); assertEquals(Model.ValueType.STRING, kvArrayS.getVType()); }