コード例 #1
0
  /*
   * PrinterStateReasons(Map map) constructor testing.
   */
  public final void testPrinterStateReasonsMap() {
    HashMap map = new HashMap();
    map.put(PrinterStateReason.TONER_LOW, Severity.WARNING);
    map.put(PrinterStateReason.DEVELOPER_LOW, Severity.WARNING);
    map.put(PrinterStateReason.MEDIA_LOW, Severity.ERROR);
    reasons = new PrinterStateReasons(map);

    assertEquals(3, reasons.size());
    assertTrue(reasons.containsKey(PrinterStateReason.TONER_LOW));
    assertTrue(reasons.containsKey(PrinterStateReason.DEVELOPER_LOW));
    assertTrue(reasons.containsKey(PrinterStateReason.MEDIA_LOW));

    try {
      map = new HashMap();
      map.put(PrinterStateReason.MEDIA_LOW, PrinterState.IDLE);
      reasons = new PrinterStateReasons(map);
      fail(
          "Constructor doesn't throw ClassCastException if "
              + "some value in the map isn't Severity");
    } catch (ClassCastException e) {
    }

    try {
      map = new HashMap();
      map.put(PrinterState.IDLE, Severity.ERROR);
      reasons = new PrinterStateReasons(map);
      fail(
          "Constructor doesn't throw ClassCastException if "
              + "some key in the map isn't PrinterStateReason");
    } catch (ClassCastException e) {
    }

    try {
      map = new HashMap();
      Severity severity = null;
      map.put(PrinterStateReason.COVER_OPEN, severity);
      reasons = new PrinterStateReasons(map);
      fail("Constructor doesn't throw NullPointerException if " + "some key in the map is null");
    } catch (NullPointerException e) {
    }

    try {
      map.put(null, Severity.REPORT);
      reasons = new PrinterStateReasons(map);
      fail("Constructor doesn't throw NullPointerException if " + "some value in the map is null");
    } catch (NullPointerException e) {
    }

    try {
      map = null;
      reasons = new PrinterStateReasons(map);
      fail("Constructor doesn't throw NullPointerException if " + "map is null");
    } catch (NullPointerException e) {
    }
  }
コード例 #2
0
 /*
  * PrinterStateReasons() constructor testing.
  */
 public final void testPrinterStateReasons() {
   reasons = new PrinterStateReasons();
   assertEquals(0, reasons.size());
 }