### Question:
ProductPartitionNode { @Override public String toString() { Long parentPartitionId = getParent() != null ? getParent().getProductPartitionId() : null; return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("dimension", toString(dimension)) .append("partitionId", partitionId) .append("parentPartitionId", parentPartitionId) .append("nodeType", nodeState.getNodeType()) .append("bidMicros", getBid()) .append("hasChildren", hasChildren()) .append("trackingUrlTemplate", getTrackingUrlTemplate()) .append("customParameters", nodeState.getCustomParams()) .toString(); } ProductPartitionNode(@Nullable ProductPartitionNode parentNode,
      @Nullable ProductDimension dimension, @Nullable Long partitionId,
      Comparator<? super ProductDimension> comparator); ProductDimension getDimension(); @Nullable Long getProductPartitionId(); boolean isSubdivision(); boolean isUnit(); ProductPartitionNode asSubdivision(); Iterable<ProductPartitionNode> getChildren(); ProductPartitionNode getChild(ProductDimension dimension); boolean hasChild(ProductDimension dimension); @Nullable Long getBid(); boolean isBiddableUnit(); boolean isExcludedUnit(); @Override String toString(); String toDetailedString(); static String toString(ProductDimension dimension); ProductPartitionNode getParent(); ProductPartitionNode addChild(ProductDimension childDimension); ProductPartitionNode removeChild(ProductDimension childDimension); ProductPartitionNode removeAllChildren(); ProductPartitionNode asExcludedUnit(); ProductPartitionNode asBiddableUnit(); ProductPartitionNode setBid(@Nullable Long bidInMicros); @Nullable String getTrackingUrlTemplate(); ProductPartitionNode setTrackingUrlTemplate(String trackingUrlTemplate); ProductPartitionNode putCustomParameter(String key, String value); @Nullable String getCustomParameter(String key); ImmutableMap<String, String> getCustomParameters(); ProductPartitionNode removeCustomParameter(String key);  }### Answer:
@Test public void testDimensionToString() throws Exception { Set<Class<? extends ProductDimension>> dimensionSubclasses = ProductDimensionsTest.getAllProductDimensionFactoryMethods().keySet(); Map<Class<? extends ProductDimension>, ProductDimension> dimensionsByType = Maps.newHashMap(); dimensionsByType.put(ProductBrand.class, ProductDimensions.createBrand("testBrand")); dimensionsByType.put(ProductBiddingCategory.class, ProductDimensions.createBiddingCategory(ProductDimensionType.BIDDING_CATEGORY_L1, 123L)); dimensionsByType.put(ProductCanonicalCondition.class, ProductDimensions.createCanonicalCondition(ProductCanonicalConditionCondition.NEW)); dimensionsByType.put(ProductChannel.class, ProductDimensions.createChannel(ShoppingProductChannel.LOCAL)); dimensionsByType.put(ProductChannelExclusivity.class, ProductDimensions .createChannelExclusivity(ShoppingProductChannelExclusivity.SINGLE_CHANNEL)); dimensionsByType.put(ProductCustomAttribute.class, ProductDimensions.createCustomAttribute( ProductDimensionType.CUSTOM_ATTRIBUTE_2, "testAttribute")); dimensionsByType.put(ProductOfferId.class, ProductDimensions.createOfferId("testOfferId")); dimensionsByType.put(ProductType.class, ProductDimensions.createType(ProductDimensionType.PRODUCT_TYPE_L3, "testType")); for (Class<? extends ProductDimension> dimensionSubclass : dimensionSubclasses) { ProductDimension sampleDimension = dimensionsByType.get(dimensionSubclass); assertNotNull("No sample dimension found for ProductDimension subclass " + dimensionSubclass + ". Add a sample instance of this type to the dimensionsByType map in this test.", sampleDimension); String dimensionToString = ProductPartitionNode.toString(sampleDimension); assertThat("ProductPartitionNode.toString does not appear to recognize any attributes of " + dimensionSubclass, dimensionToString, Matchers.not(Matchers.containsString("[]"))); assertThat("ProductPartitionNode.toString failed to interpret the attributes of a " + dimensionSubclass, dimensionToString, Matchers.not(Matchers.containsString("UNKNOWN"))); } }
@Test public void testDimensionToString_unknownAttribute() throws Exception { ProductBrand productBrand = mock(ProductBrand.class); when(productBrand.getValue()).thenThrow(new RuntimeException()); assertThat("ProductPartitionNode did not fail gracefully when interpreting the attributes of " + "a malformed ProductDimension", ProductPartitionNode.toString(productBrand), Matchers.containsString("UNKNOWN")); }