title: JUnit testing of java Equal method
body: <p>I wrote this code but I am still new in JUnit and have no idea of testing equal and equal2 method. Below is the code I wrote.  My object in this code is to see if the fname is equal to lname using equal method and by using equal2 to check if fname is same as fname(it self) maybe my code have errors too.</p>
  
  <pre><code>public class EqualMethods {
  
      /**
       * @param args
       */
  
      private String fname;
      private String lname;
  
      public EqualMethods(String fl)
      {
          fname = fl;
  
      }
  
      public EqualMethods(String f, String l)
      {
          fname = f;
          lname = l;
      }
  
  
      public String getFname() {
          return fname;
      }
  
      public String getLname()
      {
          return lname;
      }
  
      public void setLname(String lname)
      {
          this.lname = lname;
      }
  
  
  
      public void setFname(String fname) {
          this.fname = fname;
      }
  
  
      public int equal(EqualMethods name)
      {
          if(fname == name.getFname() && lname == name.getLname())
          {
  
              return 1;
          }
          else
          {
              return 0;
          }
      }
  
      public int equal2(Object o)
      {
          if(o.getClass() == EqualMethods.class )
          {
              EqualMethods e = (EqualMethods) o;
              if(this.fname.equals(e.fname))
              {
                  return 1;
              }
  
              return 0;
          }
          return 0;
      }
      public String toString()
      {
          return (" My first name is: "+fname + "  Last name is:  " + lname);
      }</code></pre>
  
  <p>The objective is to create a Junit test case to equal and equal2 as the test case i created does not provide a proper output.Here is the JUnit test case I wrote but I cant make my method static though how to get around it?</p>
  
  <pre><code>public class EqualMethodsTest extends TestCase{
  
      @Test
      public void testEqual2() {
          String name = "goma";
          int ret = 1;
          int ans ;
  
          ans= EqualMethods.equal2(name);
  
          assertEquals(ret,ans);
  
      }
  
  }</code></pre>