### Question:
MetricAdapter { static List<ResourceMetrics> toProtoResourceMetrics(Collection<MetricData> metricData) { Map<Resource, Map<InstrumentationLibraryInfo, List<Metric>>> resourceAndLibraryMap = groupByResourceAndLibrary(metricData); List<ResourceMetrics> resourceMetrics = new ArrayList<>(resourceAndLibraryMap.size()); for (Map.Entry<Resource, Map<InstrumentationLibraryInfo, List<Metric>>> entryResource : resourceAndLibraryMap.entrySet()) { List<InstrumentationLibraryMetrics> instrumentationLibraryMetrics = new ArrayList<>(entryResource.getValue().size()); for (Map.Entry<InstrumentationLibraryInfo, List<Metric>> entryLibrary : entryResource.getValue().entrySet()) { instrumentationLibraryMetrics.add( InstrumentationLibraryMetrics.newBuilder() .setInstrumentationLibrary( CommonAdapter.toProtoInstrumentationLibrary(entryLibrary.getKey())) .addAllMetrics(entryLibrary.getValue()) .build()); } resourceMetrics.add( ResourceMetrics.newBuilder() .setResource(ResourceAdapter.toProtoResource(entryResource.getKey())) .addAllInstrumentationLibraryMetrics(instrumentationLibraryMetrics) .build()); } return resourceMetrics; } private  MetricAdapter();   }### Answer:
@Test void toProtoResourceMetrics() { Resource resource = Resource.create(Attributes.of(stringKey("ka"), "va")); io.opentelemetry.proto.resource.v1.Resource resourceProto = io.opentelemetry.proto.resource.v1.Resource.newBuilder() .addAllAttributes( singletonList( KeyValue.newBuilder() .setKey("ka") .setValue(AnyValue.newBuilder().setStringValue("va").build()) .build())) .build(); io.opentelemetry.proto.resource.v1.Resource emptyResourceProto = io.opentelemetry.proto.resource.v1.Resource.newBuilder().build(); InstrumentationLibraryInfo instrumentationLibraryInfo = InstrumentationLibraryInfo.create("name", "version"); InstrumentationLibrary instrumentationLibraryProto = InstrumentationLibrary.newBuilder().setName("name").setVersion("version").build(); InstrumentationLibrary emptyInstrumentationLibraryProto = InstrumentationLibrary.newBuilder().setName("").setVersion("").build(); Metric metricNoPoints = Metric.newBuilder().setName("name").setDescription("description").setUnit("1").build(); assertThat( MetricAdapter.toProtoResourceMetrics( ImmutableList.of( MetricData.create( resource, instrumentationLibraryInfo, "name", "description", "1", MetricData.Type.MONOTONIC_DOUBLE, Collections.emptyList()), MetricData.create( resource, instrumentationLibraryInfo, "name", "description", "1", MetricData.Type.MONOTONIC_DOUBLE, Collections.emptyList()), MetricData.create( Resource.getEmpty(), instrumentationLibraryInfo, "name", "description", "1", MetricData.Type.MONOTONIC_DOUBLE, Collections.emptyList()), MetricData.create( Resource.getEmpty(), InstrumentationLibraryInfo.getEmpty(), "name", "description", "1", MetricData.Type.MONOTONIC_DOUBLE, Collections.emptyList())))) .containsExactlyInAnyOrder( ResourceMetrics.newBuilder() .setResource(resourceProto) .addAllInstrumentationLibraryMetrics( singletonList( InstrumentationLibraryMetrics.newBuilder() .setInstrumentationLibrary(instrumentationLibraryProto) .addAllMetrics(ImmutableList.of(metricNoPoints, metricNoPoints)) .build())) .build(), ResourceMetrics.newBuilder() .setResource(emptyResourceProto) .addAllInstrumentationLibraryMetrics( ImmutableList.of( InstrumentationLibraryMetrics.newBuilder() .setInstrumentationLibrary(emptyInstrumentationLibraryProto) .addAllMetrics(singletonList(metricNoPoints)) .build(), InstrumentationLibraryMetrics.newBuilder() .setInstrumentationLibrary(instrumentationLibraryProto) .addAllMetrics(singletonList(metricNoPoints)) .build())) .build()); }