Question
Using eclipse, create the user and the account classes Create a week02 project in Eclipse Create a subpackage called app (in Eclipse it will need
Using eclipse, create the user and the account classes
Create a week02 project in Eclipse
Create a subpackage called app (in Eclipse it will need to be named wekk02.app)
provided: week02.JUnitAccountTest.java week02.JUnitUserTest.java week02JUnitJavadocValidation.java week02.TestHarness.java
Implement User.java and Account.java
User and Account Classes
package week02;
import static org.junit.Assert.*;
import org.junit.Test;
import test.AbstractJUnitBase;
import week02.app.Account;
import week02.app.User;
public class JUnitAccountTest extends AbstractJUnitBase
{
@Test
public void testAccountEqualsOverride()
{
// simple user creation
Account account1 = new Account();
trace("Testing default constructor generates identical objects");
Account account2 = new Account();
// expect to be same
String msg = String.format("Accounts not equal %s %s", account1, account2);
assertTrue(msg, account1.equals(account2));
trace("Testing setter methods to change one object");
User newUser = new User(1, "Jim","Bo");
account2.setName("Test Acouunt");
account2.setUser(newUser);
msg = String.format("Accounts should not be equal %s %s", account1, account2);
assertFalse(msg, account1.equals(account2));
trace("Testing parameterized constructor with data from existing object");
Account account3 = new Account(2, newUser, "Test Account 2", 1000.0);
String toString = account3.toString();
trace("Testing toString for new account: " + account3.toString());
boolean invalidFormat = toString.contains("Account@");
trace("toString test " + invalidFormat);
assertFalse("Account doesn't properly override toString " + toString, invalidFormat);
}
}
package week02;
import static org.junit.Assert.*;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import test.TestResult;
import test.TestResultDetail;
import test.javadoc.ConstructorTestData;
import test.javadoc.FileTestData2;
import test.javadoc.JUnitJavadocValidationUtility2;
import test.javadoc.MethodTestData2;
/**
* Tests the Javadoc in the source file.
*
* @author Scott
*
*/
public class JUnitJavadocValidation
{
public JUnitJavadocValidation()
{
m_stream = System.out; // Standard out
trace("########### Initializing JUnitJavadocValidation for week02 ###########");
List
List
List
constructors.add(new ConstructorTestData("User", 0, "public"));
constructors.add(new ConstructorTestData("User",3, "public"));
methods.add(new MethodTestData2("equals", "Object", "boolean","public"));
methods.add(new MethodTestData2("getFirstName", "", "String","public"));
methods.add(new MethodTestData2("getLastName", "", "String","public"));
methods.add(new MethodTestData2("getUserId", "", "long","public"));
methods.add(new MethodTestData2("setFirstName", "String", "void","public"));
methods.add(new MethodTestData2("setLastName", "String", "void","public"));
methods.add(new MethodTestData2("setUserId", "long", "void","public"));
methods.add(new MethodTestData2("toString", "", "String","public"));
testFiles.add(new FileTestData2("week02.app", "User.java", methods,constructors));
List
List
accountConstructors.add(new ConstructorTestData("Account", 0, "public"));
accountConstructors.add(new ConstructorTestData("Account",4, "public"));
accountMethods.add(new MethodTestData2("equals", "Object", "boolean","public"));
accountMethods.add(new MethodTestData2("getAccountId", "", "long","public"));
accountMethods.add(new MethodTestData2("getBalance", "", "double","public"));
accountMethods.add(new MethodTestData2("getName", "", "String","public"));
accountMethods.add(new MethodTestData2("getUser", "", "User","public"));
accountMethods.add(new MethodTestData2("getUserId", "", "long","public"));
accountMethods.add(new MethodTestData2("setName", "String", "void","public"));
accountMethods.add(new MethodTestData2("setUser", "User", "void","public"));
accountMethods.add(new MethodTestData2("toString", "", "String","public"));
testFiles.add(new FileTestData2("week02.app", "Account.java", accountMethods,accountConstructors));
m_validator = new JUnitJavadocValidationUtility2("Week02 Javadoc Test",
testFiles);
m_validator.suppressParserTrace(true);
}
@Test
public void testJavadoc()
{
trace("** Validating Javadoc **");
// Update these values for each assignment
// m_packageName = "week02";
TestResult result = m_validator.runTest();
StringBuilder details = new StringBuilder();
if(!result.passed())
{
List
for(TestResultDetail detail : detailList)
{
trace(detail.testDetails());
details.append(detail.testDetails());
details.append(CRLF);
}
}
trace(String.format("** Test result: %s **", result.passed() ? "Passed" : "Failed"));
assertTrue(details.toString(), result.passed());
}
/**
* Trace the msg to a PrintStream Provides the method for tests to report
* status
*
* @param msg
*/
private void trace(String msg)
{
m_stream.println(msg);
}
private JUnitJavadocValidationUtility2 m_validator;
protected PrintStream m_stream;
private static String CRLF = System.getProperty("line.separator");
}
package week02;
import static org.junit.Assert.*;
//import java.io.PrintStream;
import org.junit.Test;
import test.AbstractJUnitBase;
import week02.app.User;
public class JUnitUserTest extends AbstractJUnitBase
{
/**
* Constructor
*/
public JUnitUserTest()
{
m_stream = System.out; // Standard out
trace("########### Initializing JUnitUserTest for week02 ###########");
}
@Test
public void testUserEqualsOverride()
{
// simple user creation
User user = new User();
trace("Testing default constructor generates identical objects");
User user2 = new User();
// expect to be same
String msg = String.format("Users not equal %s %s", user, user2);
assertTrue(msg, user.equals(user2));
trace("Testing setter methods to change one object");
user2.setFirstName("Jim");
user2.setLastName("Bo");
user2.setUserId(1);
msg = String.format("Users should not be equal %s %s", user, user2);
assertFalse(msg, user.equals(user2));
trace("Testing parameterized constructor with data from existing object");
User user3 = new User(user2.getUserId(), user2.getFirstName(), user2.getLastName());
trace(user3.toString());
msg = String.format("Users should equal %s %s", user, user2);
assertTrue(msg, user3.equals(user2));
}
}
package week02;
import test.AbstractTestHarness;
/**
* File: TestHarness.java
*/
class TestHarness extends AbstractTestHarness
{
public static void main(String[] args)
{
new TestHarness().runTests();
}
/**
* Implements the base class abstract method
*/
protected void runTests()
{
try
{
boolean javadocTest = executeTest(JUnitJavadocValidation.class);
boolean userTest = executeTest(JUnitUserTest.class);
boolean accountTest = executeTest(JUnitAccountTest.class);
boolean result = javadocTest && userTest && accountTest;
trace(result ? "PASSED" : "FAILED");
}
catch(Exception ex)
{
trace(ex.getMessage());
}
}
}
class app Name: app Package: app Version: 1.0 Author: Scott LaChance Account m firstName: String m lastName: String m accountName: String m balance: double + equals(Object]: boolean + getLastName(): String + setFirstName(String): void -m usergetFirstName):String + Accountlong, User, String, double) + equals(Object) boolean + setLastName(String): void + getName(): String + setName(String): void + set Userllong, String, String) + User(User: void
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started