title: How to Trigger a ClassCastException? I'm trying to unit test a class and there is this try/catch segment which i'm not able to check
body: <pre class="lang-java prettyprint-override"><code>public int compare(Cat cat1, Cat cat2) {
  
          try {
              Cat obj1 = cat1;
              Cat obj2 = cat2;
              return obj1.getCode().compareTo(obj2.getCode());
              //compareTo returns 0/1, getCode returns a string color of cat.
          } 
          catch (ClassCastException e) {
              throw new CatRuntimeException(&quot;Comparison failed.&quot;);
          }
  }
   //want to test the catch part.       
  </code></pre>