Question: HELP WITH THIS import org.junit.*; import org.junit.runner.*; import static org.junit.Assert.*; public class Main { public static void main(String[] args) { //System.out.println(Look at the README!); SocialMediaProfile

HELP WITH THIS

import org.junit.*;

import org.junit.runner.*;

import static org.junit.Assert.*;

public class Main {

public static void main(String[] args) {

//System.out.println("Look at the README!");

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

//You can write your test code here

//System.out.println(x);

//*******UNCOMMENT THE FOLLOWING LINE AND THE TEST CASES BELOW WHEN YOU ARE READY TO TEST******//

org.junit.runner.JUnitCore.main("Main");

}

//***UNCOMMENT THESE TESTS WHEN YOU ARE READY TO TEST!****//

@Test

public void Constructor_and_getname() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then ensures that the getname returns Sandy

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

assertTrue(myProfile.getname().equals("Sandy"));

}

@Test

public void Constructor_and_getcountry() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then ensures that the getcountry returns USA

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

assertEquals(myProfile.getcountry(), "USA");

}

@Test

public void Constructor_and_getNumberOfPosts() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then ensures that the getnumberOfPosts returns 50

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

assertEquals(myProfile.getnumberOfPosts(), 50);

}

@Test

public void toString_Test() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then runs toString and checks if the string returned is correct

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

assertEquals(myProfile.toString(),"name:Sandy, age:23, country:USA, numberOfPosts:50, numberOfLikes:110, averageLikesPerPost:2.2");

}

@Test

public void setname_and_setage() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then changes the name to Sandy Blake using setname and then sets age to 40, and finally sets age to a negative number (should stay 40).

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

myProfile.setname("Sandy Blake");

assertEquals(myProfile.getname(),"Sandy Blake");

myProfile.setage(40);

assertEquals(myProfile.getage(),40);

myProfile.setage(-3);

assertEquals(myProfile.getage(),40);

}

@Test

public void averageLikesPerPost_Test() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then calls averageLikesPerPost and then changes number of Posts to 0 and calls averageLikesPerPost. Beware of divide by zero errors!

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

assertEquals(myProfile.averageLikesPerPost(),2.2,.01);

myProfile.setnumberOfPosts(0);

assertEquals(myProfile.averageLikesPerPost(),0,.01);

}

@Test

public void setCountry_setPosts_setLikes() {

// Failure message:

// The test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110 and then sets the country to Mexico, sets the Posts to 23, then sets the posts to -3 (should stay 23), then sets the the number of likes to 44, then sets the number of likes to -3 (should stay unchanged

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

myProfile.setcountry("Mexico");

assertEquals(myProfile.getcountry(),"Mexico");

myProfile.setnumberOfPosts(23);

assertEquals(myProfile.getnumberOfPosts(),23);

myProfile.setnumberOfPosts(-3);

assertEquals(myProfile.getnumberOfPosts(),23);

myProfile.setnumberOfLikes(44);

assertEquals(myProfile.getnumberOfLikes(),44);

myProfile.setnumberOfLikes(-3);

assertEquals(myProfile.getnumberOfLikes(),44);

}

@Test

public void equals_Test() {

// Failure message:

// This test creates a SocialMediaProfile object with name Sandy, age 23, country USA, numberOfPosts 50, and numberOfLikes 110. It then creates another identical object and checks if they are equal. Then it sets one of the objects names to randy and checks if thats equal to the first object (it shouldn't be). Finally it checks equality with a different class altogether (this should also not be equal).

SocialMediaProfile myProfile= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

SocialMediaProfile myProfile2= new SocialMediaProfile("Sandy", 23, "USA", 50, 110);

assertEquals(myProfile,myProfile2);

myProfile2.setname("Randy");

assertFalse(myProfile.equals(myProfile2));

assertFalse(myProfile.equals("this is a random string"));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!