fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class BrokenEncapsulationTest {
  8.  
  9. public void testAddCount() {
  10. InstrumentedHashSet<String> set = new InstrumentedHashSet<String>();
  11.  
  12. set.addAll(Arrays.asList("Snap", "Crackle", "Pop"));
  13.  
  14. if(3 == set.addCount) System.out.println("Yeh fuck yeh");
  15. else System.out.println(set.addCount);
  16. //assertEquals(3, set.addCount);
  17. }
  18.  
  19. public static class InstrumentedHashSet<E> extends HashSet<E> {
  20.  
  21. public int addCount = 0;
  22.  
  23. @Override
  24. public boolean add(E a) {
  25. addCount += 1;
  26. return super.add(a);
  27. };
  28.  
  29. @Override
  30. public boolean addAll(Collection<? extends E> c) {
  31. addCount += c.size();
  32. return super.addAll(c);
  33. }
  34. }
  35. }
  36.  
  37. /* Name of the class has to be "Main" only if the class is public. */
  38. class Ideone
  39. {
  40. public static void main (String[] args) throws java.lang.Exception
  41. {
  42. // your code goes here
  43. BrokenEncapsulationTest a = new BrokenEncapsulationTest();
  44. a.testAddCount();
  45. }
  46. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
6