コード例 #1
0
  @Test
  public void removeNegativeNumber() throws Exception {
    // Given addressbook with one entry
    controller.add(johnData[0], johnData[1], johnData[2], johnData[3], johnData[4]);
    int sizeBefore = model.getEntries().size();

    // When
    controller.remove(-1);

    // Then everything should still be fine
    int sizeAfter = model.getEntries().size();
    assertThat(sizeAfter, is(equalTo(sizeBefore)));
  }
コード例 #2
0
  /**
   * Während wir den Test geschrieben haben, ist uns aufgefallen, dass die Implementierung von Entry
   * geändert wurde und jetzt der Nachname als erster Parameter übergeben wird.
   *
   * @see AddressBookControllerTest
   */
  @Test
  public void add() throws ParameterException, SizeLimitReachedException {
    // Given
    Entry johnEntry = new Entry("Doe", "John", Gender.Male, new PhoneNumber(123456789));
    int sizeOfmodel = model.getEntries().size();
    ArgumentCaptor<Entry> entryAdded = ArgumentCaptor.forClass(Entry.class);

    // When adding John via controller
    this.controller.add(johnData[0], johnData[1], johnData[2], johnData[3], johnData[4]);

    // Then model is updated
    verify(model).addEntry(entryAdded.capture());
    assertThat(entryAdded.getValue(), is(johnEntry));
    assertThat(model.getEntries().size(), is(sizeOfmodel + 1));
    assertThat(model.getEntries().contains(johnEntry), is(true));
  }
コード例 #3
0
  @Test
  public void removeOneEntry() throws Exception {
    // Given addressbook with some entry, added in non alphebetic order
    this.controller.add(johnData[0], johnData[1], johnData[2], johnData[3], johnData[4]);
    this.controller.add(aliceData[0], aliceData[1], aliceData[2], aliceData[3], aliceData[4]);
    this.controller.add(bobData[0], bobData[1], bobData[2], bobData[3], bobData[4]);
    int sizeBefor = model.getEntries().size();
    // Entries are ordered by surname and firstname (ascending).

    // When removing john
    controller.remove(2);

    // Then
    Entry johnEntry = new Entry("Doe", "John", Gender.Male, new PhoneNumber(123456789));
    verify(model).deleteEntry(eq(johnEntry));
    assertThat(model.getEntries().size(), is(equalTo(sizeBefor - 1)));
  }
コード例 #4
0
  @Test
  /**
   * Fehler: Die Spezifikation oder das JavaDoc sagt nichts über eine Exception. "The entry number
   * is not allowed to refer to a non existing entry." Es sei denn man interpretiert "is not
   * allowed" als Definition von Exception werfen.
   */
  public void removeTooHighNumber() throws Exception {
    // Given addressbook with one entry
    controller.add(johnData[0], johnData[1], johnData[2], johnData[3], johnData[4]);
    int sizeBefore = model.getEntries().size();

    // When
    controller.remove(1);

    // Then everything should still be fine
    int sizeAfter = model.getEntries().size();
    assertThat(sizeAfter, is(equalTo(sizeBefore)));
  }
コード例 #5
0
  @Test
  /** This will fail because erase's while condition is wrong. */
  public void erase() throws Exception {
    // Given addressbook with some entry, added in non alphebetic order
    this.controller.add(johnData[0], johnData[1], johnData[2], johnData[3], johnData[4]);
    this.controller.add(aliceData[0], aliceData[1], aliceData[2], aliceData[3], aliceData[4]);
    this.controller.add(bobData[0], bobData[1], bobData[2], bobData[3], bobData[4]);

    // When
    controller.erase();

    // Then
    // verify(model).erase(); I expected controller.erase, would just call model.erase
    verify(model, times(3)).deleteEntry(any(Entry.class));
    assertThat(model.getEntries().size(), is(0));
  }