### Question:
ResourceSpec implements Serializable { public ResourceSpec merge(ResourceSpec other) { if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } ResourceSpec target = new ResourceSpec( Math.max(this.cpuCores, other.cpuCores), this.heapMemoryInMB + other.heapMemoryInMB, this.directMemoryInMB + other.directMemoryInMB, this.nativeMemoryInMB + other.nativeMemoryInMB, this.stateSizeInMB + other.stateSizeInMB, this.managedMemoryInMB + other.managedMemoryInMB); target.extendedResources.putAll(extendedResources); for (Resource resource : other.extendedResources.values()) { target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.merge(v2)); } return target; } private  ResourceSpec(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int stateSizeInMB,
			int managedMemoryInMB,
			Resource... extendedResources); private  ResourceSpec(); ResourceSpec merge(ResourceSpec other); double getCpuCores(); int getHeapMemory(); int getDirectMemory(); int getNativeMemory(); int getStateSize(); int getManagedMemory(); double getGPUResource(); Map<String, Resource> getExtendedResources(); boolean isValid(); boolean lessThanOrEqual(@Nonnull ResourceSpec other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Builder newBuilder(); static final ResourceSpec UNKNOWN; static final ResourceSpec DEFAULT; static final String GPU_NAME; }### Answer:
@Test public void testMerge() throws Exception { ResourceSpec rs1 = ResourceSpec.newBuilder(). setCpuCores(1.0). setHeapMemoryInMB(100). setGPUResource(1.1). build(); ResourceSpec rs2 = ResourceSpec.newBuilder().setCpuCores(1.0).setHeapMemoryInMB(100).build(); ResourceSpec rs3 = rs1.merge(rs2); assertEquals(1.1, rs3.getGPUResource(), 0.000001); ResourceSpec rs4 = rs1.merge(rs3); assertEquals(2.2, rs4.getGPUResource(), 0.000001); }
@Test public void testMergeBothUnknown() throws Exception { final ResourceSpec spec1 = ResourceSpec.UNKNOWN; final ResourceSpec spec2 = ResourceSpec.UNKNOWN; final ResourceSpec merged = spec1.merge(spec2); assertEquals(ResourceSpec.UNKNOWN, merged); }
@Test public void testMergeWithSerializationCopy() throws Exception { final ResourceSpec spec1 = CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN); final ResourceSpec spec2 = CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN); final ResourceSpec merged = spec1.merge(spec2); assertEquals(ResourceSpec.UNKNOWN, merged); }