Skip to content

TestClass for Chapter 6's code #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions chap06/DotComBustTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package chap06;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.ArrayList;

import org.junit.Test;

import mockit.Deencapsulation;

public class DotComBustTest {
private DotComBust dotComBust = new DotComBust();
@Test
public void testSetupGame() {
Deencapsulation.invoke(dotComBust, "setUpGame");
ArrayList<DotCom> expectedList = new ArrayList<DotCom>();
DotCom one = new DotCom();
one.setName("Pets.com");
DotCom two = new DotCom();
two.setName("eToys.com");
DotCom three = new DotCom();
three.setName("Go2.com");
expectedList.add(one);
expectedList.add(two);
expectedList.add(three);
ArrayList<DotCom> actualList = Deencapsulation.getField(dotComBust, "dotComsList");
assertEquals(actualList.size(), 3);
int numberOfMatches = 0;
for(DotCom actual:actualList){
for(DotCom expected:expectedList){
if(Deencapsulation.getField(expected, "name").equals(Deencapsulation.getField(actual, "name"))){
numberOfMatches = numberOfMatches+1;
}
}
}
//checks it has exact match
assertEquals(numberOfMatches, 3);
//check if locations are set for each item
for(DotCom actual:actualList){
assertNotNull(Deencapsulation.getField(actual, "locationCells"));
assertEquals(((ArrayList<DotCom>) Deencapsulation.getField(actual, "locationCells")).size(),3);
}
}

}