Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this quotation i did not understand how i solve can any one help me

//please pass the test cases by modifying the ValueObject class only

What I have tried:

main

class ValueObject {

}


public class ValueObjectTest {
    @Test
    public void givenTwoValueObjectsWithSameValues_whenCompare_thenTheyAreEqual() {
        Name name1 = new Name("john", "peter");
        Name name2 = new Name("john", "peter");
        assertEquals(name1, name2);
        assertEquals(0, name1.compareTo(name2));
    }

    @Test
    public void givenTwoValueObjectsWithDifferentValues_whenCompare_thenTheyAreNotEqual() {
        Name name1 = new Name("peter", "john");
        Name name2 = new Name("john", "peter");
        assertNotEquals(name1, name2);
        assertNotEquals(0, name1.compareTo(name2));
    }

    @Test
    public void givenValueObject_whenToString_thenToStringShowStructure() {
        assertEquals("Id{id=null}", new Id(null).toString());
        assertEquals("Id{id=1}", new Id("1").toString());
        assertEquals("Id{id=2}", new Id("2").toString());
        assertEquals("Name{first=peter, last=john}", new Name("peter", "john").toString());
    }

    private static class Name extends ValueObject {
        private Name(String first, String last) {
            super("first", first, "last", last);
        }
    }

    private static class Address extends ValueObject {
        private Address(String line1, String line2, String POBox) {
            super("line1", line1, "line2", line2, "POBox", POBox);
        }
    }


    private static class Id extends ValueObject {
        private Id(String id) {
            super("id", id);
        }
    }
}
Posted
Updated 6-Nov-19 2:49am
v2
Comments
Richard MacCutchan 6-Nov-19 5:31am    
Since you have not shown the ValueObject class then it is impossible to make any suggestions.
coderom2019 6-Nov-19 5:34am    
This is the Whole assignment
Richard MacCutchan 6-Nov-19 7:58am    
You say, "//please pass the test cases by modifying the ValueObject class only".
So how can you change the ValueObject class if you do not have it?
coderom2019 6-Nov-19 8:45am    
I have but it is empty

class ValueObject {

}

like this .

this is a assignment and they are send like this
coderom2019 6-Nov-19 8:46am    
So maybe the answer will be cannot Chang the ValueObject class ?

1 solution

Here is a tutorial for the TestNG framework: Introduction to Unit Testing with Java - DEV Community 👩‍💻👨‍💻[^]

And here for the JUnit framework: Unit Testing in Java with JUnit 5[^]
 
Share this answer
 
v2
Comments
coderom2019 6-Nov-19 5:34am    
thank you i will see

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900