예제 #1
0
 @Test
 public void testGetName() {
   // fail("Not yet implemented");
   Person p = new Person("Last", "First");
   String name = p.getName();
   assertEquals(name, "First Last");
 }
예제 #2
0
 @Test
 public void testGetPerson() {
   Book b1 = new Book("Learn SQL");
   Person p1 = new Person("John Doe");
   b1.setPerson(p1);
   Person testPerson = b1.getPerson();
   assertEquals(p1, testPerson);
   assertEquals("John Doe", testPerson.getName());
 }
예제 #3
0
 @Test
 public void sortByExample3() {
   // We have the names of some people in the right order, but then we want to sort the actual
   // Person objects
   // into the same order.  Providing a mapping function from the Person to his/her name is all we
   // need.
   final Person huey = new Person("huey");
   final Person dewey = new Person("dewey");
   final Person louie = new Person("louie");
   List<String> example = asList("donald", huey.getName(), dewey.getName(), louie.getName());
   assertEquals(
       asList(huey, dewey, louie),
       Algorithms.sortByExample(
           example,
           asList(dewey, louie, huey),
           new Function<Person, String>() {
             public String apply(Person p) {
               return p.getName();
             }
           }));
 }
  @Test
  public void multipleOperations_ShouldReturnWorkCorrectly() {
    boolean isAdded = persons.addPerson("*****@*****.**", "Pesho", 28, "Plovdiv");
    assertTrue(isAdded);
    assertEquals(1, persons.size());

    isAdded = persons.addPerson("*****@*****.**", "Pesho2", 222, "Plovdiv222");
    assertFalse(isAdded);
    assertEquals(1, persons.size());

    persons.addPerson("*****@*****.**", "Kiril", 22, "Plovdiv");
    assertEquals(2, persons.size());

    persons.addPerson("*****@*****.**", "Asen", 22, "Sofia");
    assertEquals(3, persons.size());

    Person person = persons.findPerson("non-existing person");
    assertNull(person);

    person = persons.findPerson("*****@*****.**");
    assertNotNull(person);
    assertEquals("*****@*****.**", person.getEmail());
    assertEquals("Pesho", person.getName());
    assertEquals(28, person.getAge());
    assertEquals("Plovdiv", person.getTown());

    List<Person> personsGmail = (List<Person>) persons.findPersons("gmail.com");
    assertArrayEquals(
        new String[] {"*****@*****.**", "*****@*****.**"},
        personsGmail.stream().map(p -> p.getEmail()).toArray());

    List<Person> personsPeshoPlovdiv = (List<Person>) persons.findPersons("Pesho", "Plovdiv");
    assertArrayEquals(
        new String[] {"*****@*****.**"},
        personsPeshoPlovdiv.stream().map(p -> p.getEmail()).toArray());

    List<Person> personsPeshoSofia = (List<Person>) persons.findPersons("Pesho", "Sofia");
    assertEquals(0, personsPeshoSofia.size());

    List<Person> personsKiroPlovdiv = (List<Person>) persons.findPersons("Kiro", "Plovdiv");
    assertEquals(0, personsKiroPlovdiv.size());

    List<Person> personsAge22To28 = (List<Person>) persons.findPersons(22, 28);
    assertArrayEquals(
        new String[] {"*****@*****.**", "*****@*****.**", "*****@*****.**"},
        personsAge22To28.stream().map(p -> p.getEmail()).toArray());

    List<Person> personsAge22To28Plovdiv = (List<Person>) persons.findPersons(22, 28, "Plovdiv");
    assertArrayEquals(
        new String[] {"*****@*****.**", "*****@*****.**"},
        personsAge22To28Plovdiv.stream().map(p -> p.getEmail()).toArray());

    boolean isDeleted = persons.deletePerson("*****@*****.**");
    assertTrue(isDeleted);

    isDeleted = persons.deletePerson("*****@*****.**");
    assertFalse(isDeleted);

    person = persons.findPerson("*****@*****.**");
    assertNull(person);

    personsGmail = (List<Person>) persons.findPersons("gmail.com");
    assertArrayEquals(
        new String[] {"*****@*****.**"}, personsGmail.stream().map(p -> p.getEmail()).toArray());

    personsPeshoPlovdiv = (List<Person>) persons.findPersons("Pesho", "Plovdiv");
    assertArrayEquals(
        new String[] {}, personsPeshoPlovdiv.stream().map(p -> p.getEmail()).toArray());

    personsPeshoSofia = (List<Person>) persons.findPersons("Pesho", "Sofia");
    assertEquals(0, personsPeshoSofia.size());

    personsKiroPlovdiv = (List<Person>) persons.findPersons("Kiro", "Plovdiv");
    assertEquals(0, personsKiroPlovdiv.size());

    personsAge22To28 = (List<Person>) persons.findPersons(22, 28);
    assertArrayEquals(
        new String[] {"*****@*****.**", "*****@*****.**"},
        personsAge22To28.stream().map(p -> p.getEmail()).toArray());

    personsAge22To28Plovdiv = (List<Person>) persons.findPersons(22, 28, "Plovdiv");
    assertArrayEquals(
        new String[] {"*****@*****.**"},
        personsAge22To28Plovdiv.stream().map(p -> p.getEmail()).toArray());
  }