View Javadoc
1   /*
2   EqualsHashCode
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.equalshashcode;
8   
9   import java.awt.*;
10  import java.io.ByteArrayOutputStream;
11  import java.io.File;
12  
13  /**
14   * Test case for detecting simple semantic violations.
15   * @author Lars Kühne
16   **/
17  class InputEqualsHashCodeSemanticTwo
18  {
19      public class EqualsVsHashCode4
20      {
21          // in anon inner class
22          ByteArrayOutputStream bos1 = new ByteArrayOutputStream()
23          {
24              public boolean equals(Object a)
25              {
26                  return true;
27              }
28  
29              public int hashCode()
30              {
31                  return 0;
32              }
33          };
34  
35          ByteArrayOutputStream bos2 = new ByteArrayOutputStream()
36          {
37              public boolean equals(Object a) // violation 'without .* of 'hashCode()'.'
38              {
39                  return true;
40              }
41          };
42      }
43  
44      public void triggerEmptyBlockWithoutBlock()
45      {
46          // an if statement without a block to increase test coverage
47          if (true)
48              return;
49      }
50  
51      // empty instance initializer
52      {
53      }
54  
55      public class EqualsVsHashCode5
56      {
57          public <A> boolean equals(int a) // wrong arg type, ok even with generics
58          {
59              return a == 1;
60          }
61      }
62  
63      public class EqualsVsHashCode6
64      {
65          public <A> boolean equals(Comparable<A> a)
66          {
67              return true;
68          }
69      }
70  }