【笔记】Eclipse and Java for Total Beginners—010

Lesson10 – Start on MyLibrary Class

  • Create MyLibrary Test JUnit test
  • Create testMyLibrary to test MyLibrary constructor
  • Create MyLibrary constructor
  • Introduce instanceof operator
  • Introduce assertTrue method

  
    
1 package org.totalbeginner.tutorial;
2
3   import java.util.ArrayList;
4
5   import junit.framework.TestCase;
6
7   public class MyLibraryTest extends TestCase {
8 public void testMyLibrary() {
9 MyLibrary ml = new MyLibrary( " Test " );
10
11 assertEquals( " Test " , ml.name);
12
13 assertTrue(ml.books instanceof ArrayList);
14 assertTrue(ml.people instanceof ArrayList);
15
16
17 }
18
19 }

  
    
1 package org.totalbeginner.tutorial;
2
3 import java.util.ArrayList;
4
5 import org.totoalbeginner.tutorial.Person;
6
7 public class MyLibrary {
8
9 String name;
10 ArrayList < Person > people;
11 ArrayList < Book > books;
12
13 public MyLibrary(String name) {
14 this .name = name;
15 books = new ArrayList < Book > ();
16 people = new ArrayList < Person > ();
17
18 }
19
20 }

你可能感兴趣的:(eclipse)