Assignment: Write a JUnit test assuming you have two StringBuffer references named sbOne and sbTwo and you only want it to pass if the two references point to the same StringBuffer object.
I want to make sure this actually a good way to approach this assignment. I wrote the assumed method for practice:
package StringBufferJUni;
public class StringBufferUni {
public static void main(String[] args){
}
public boolean StringBuff(StringBuffer sbOne, StringBuffer sbTwo){
sbTwo = sbOne;
if(sbTwo==sbOne){
return true;
}
else{
return false;
}
}
}
And this is my JUnit test:
package StringBufferJUni;
import static org.junit.Assert.*;
import org.junit.Test;
public class JUnitStringBuffer {
@Test
public void test() {
StringBuffer sbOne = new StringBuffer("hello");
StringBuffer sbTwo = new StringBuffer("hello");
StringBufferUni stBuffer = new StringBufferUni();
boolean hel = stBuffer.StringBuff(sbOne, sbTwo);
assertEquals(true, hel);
}
}
Is this actually passing due to the references pointing to the same object?