I have this JUnit test that I need help developing a Interface and Class for, here is the test:
Box b1 = new DefaultBox( "abc" ); Box b2 = new DefaultBox( "def" );
Box b3 = new DefaultBox( "" );
assertEquals("abc", b1.contents());
assertEquals("[abc]", b1.toString());
assertTrue(b1.equals(b1)); assertFalse(b1.equals(b2));
assertFalse(b1.equals(null));
assertEquals("cba", b1.flip().contents());
assertEquals("", b3.flip().contents());
can anyone help me in developing a Default box class and a box interface to make these test pass? Any help would be most appreciated.
Updates
Ok I am trying to start a constuctor but i keep getting a run time error saying “Implicit super constructor Box() is undefined. Must explicitly invoke another constructor” Here is my class:
import javax.swing.Box;
public class DefaultBox extends Box{
public DefaultBox(String string) {
}
}
my Junit test is:
import static org.junit.Assert.*;
import javax.swing.Box;
public class question3_test {
Box b1 = new DefaultBox( "abc" );
Box b2 = new DefaultBox( "def" );
Box b3 = new DefaultBox( "" );
public void testquestion3(){
assertEquals("abc", b1.contents());
assertEquals("[abc]", b1.toString());
assertTrue(b1.equals(b1)); assertFalse(b1.equals(b2));
assertFalse(b1.equals(null));
assertEquals("cba", b1.flip().contents());
assertEquals("", b3.flip().contents());
}
}
I have tried to remove the “extends Box” but then that gives me a run time error on the Junit test. Can anyone guide me on how to remove this implicit super constructor error?
What kind of help you need? Your question doesn’t seem so complex.
contentsshould return the string containedtoStringshould put it in bracketsequalsshould check if contents are equalflipshould return a newDefaultBoxwith reversed contentI suppose this is homework, but the class that you have to implement it’s quite trivial..