Search in sources :

Example 1 with ToStringTestClass

use of org.motechproject.mds.testutil.records.display.ToStringTestClass in project motech by motech.

the class DefaultCsvExportCustomizerTest method shouldFormatRelationships.

@Test
public void shouldFormatRelationships() {
    // these two relationship types should be handled the same way
    for (Class clazz : asList(OneToOneRelationship.class, ManyToOneRelationship.class)) {
        FieldDto relField = FieldTestHelper.fieldDto("name", clazz);
        assertEquals("something", exportCustomizer.formatField(relField, new UIRepresentationTestClass(1, "something")));
        assertEquals("something", exportCustomizer.formatField(relField, new ToStringTestClass(1, "something")));
        assertEquals("4", exportCustomizer.formatField(relField, new NoToString(4)));
        assertEquals("", exportCustomizer.formatField(relField, null));
    }
    // these two as well
    for (Class clazz : asList(OneToManyRelationship.class, ManyToManyRelationship.class)) {
        FieldDto relField = FieldTestHelper.fieldDto("name", clazz);
        assertEquals("first,second", exportCustomizer.formatField(relField, asList(new UIRepresentationTestClass(1, "first"), new UIRepresentationTestClass(2, "second"))));
        assertEquals("first,second", exportCustomizer.formatField(relField, asList(new ToStringTestClass(1, "first"), new ToStringTestClass(2, "second"))));
        assertEquals("7,8", exportCustomizer.formatField(relField, asList(new NoToString(7), new NoToString(8))));
        assertEquals("", exportCustomizer.formatField(relField, null));
        assertEquals("", exportCustomizer.formatField(relField, Collections.emptySet()));
    }
}
Also used : NoToString(org.motechproject.mds.testutil.records.display.NoToString) UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 2 with ToStringTestClass

use of org.motechproject.mds.testutil.records.display.ToStringTestClass in project motech by motech.

the class DisplayHelperTest method testSingleObjectRelationshipDisplay.

private void testSingleObjectRelationshipDisplay(Class<? extends Relationship> relClass) {
    FieldDto field = FieldTestHelper.fieldDto("relField", relClass);
    assertEquals("Value", DisplayHelper.getDisplayValueForField(field, new ToStringTestClass(1, "Value")));
    assertEquals("Value", DisplayHelper.getDisplayValueForField(field, new UIRepresentationTestClass(1, "Value")));
}
Also used : UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 3 with ToStringTestClass

use of org.motechproject.mds.testutil.records.display.ToStringTestClass in project motech by motech.

the class DisplayHelperTest method testMultiObjectRelationshipDisplay.

private void testMultiObjectRelationshipDisplay(Class<? extends Relationship> relClass) {
    FieldDto field = FieldTestHelper.fieldDto("relField", relClass);
    Map<Long, String> displayMap = (Map<Long, String>) DisplayHelper.getDisplayValueForField(field, asList(new ToStringTestClass(1, "val1"), new ToStringTestClass(2, "val2"), new ToStringTestClass(3, "val3")));
    assertDisplayMap(displayMap, "val1", "val2", "val3");
    displayMap = (Map<Long, String>) DisplayHelper.getDisplayValueForField(field, asList(new UIRepresentationTestClass(1, "val1"), new UIRepresentationTestClass(2, "val2"), new UIRepresentationTestClass(3, "val3")));
    assertDisplayMap(displayMap, "val1", "val2", "val3");
}
Also used : UIRepresentationTestClass(org.motechproject.mds.testutil.records.display.UIRepresentationTestClass) ToStringTestClass(org.motechproject.mds.testutil.records.display.ToStringTestClass) Map(java.util.Map) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

FieldDto (org.motechproject.mds.dto.FieldDto)3 ToStringTestClass (org.motechproject.mds.testutil.records.display.ToStringTestClass)3 UIRepresentationTestClass (org.motechproject.mds.testutil.records.display.UIRepresentationTestClass)3 Map (java.util.Map)1 Test (org.junit.Test)1 NoToString (org.motechproject.mds.testutil.records.display.NoToString)1