diff --git a/pom.xml b/pom.xml index d73c078..c77c8a3 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder Interfaces 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + @@ -15,5 +27,10 @@ 4.12 test + + io.zipcoder + Interfaces + 1.0-SNAPSHOT + diff --git a/src/main/java/io/zipcoder/Animal.java b/src/main/java/io/zipcoder/Animal.java new file mode 100644 index 0000000..eaca3c5 --- /dev/null +++ b/src/main/java/io/zipcoder/Animal.java @@ -0,0 +1,8 @@ +package io.zipcoder; + +/** + * created by Frankie on 02/26/18 + */ +public interface Animal { + String speak(); +} diff --git a/src/main/java/io/zipcoder/Application.java b/src/main/java/io/zipcoder/Application.java index 3a257cb..3deddda 100644 --- a/src/main/java/io/zipcoder/Application.java +++ b/src/main/java/io/zipcoder/Application.java @@ -1,5 +1,69 @@ package io.zipcoder; +import java.util.*; + +//April +/** + * Tests made by Frankie Rodriguez on 02/26/18 + */ + public class Application { + private String nameOfPet; + private String typeOfPet; + private Integer amountOfPets; + + + ArrayList petList = new ArrayList<>(); + + public Application() { + } + + public Application(String typeOfPet, String nameOfPet) { + this.typeOfPet = typeOfPet; + this.nameOfPet = nameOfPet; + } + + public void welcomeUser() { + System.out.println("******************** WELCOME PET OWNER **********************\n" + + "We will be asking you a couple of questions about your pets.\n" + + "No need to worry. We won't be doing anything sketchy with\n" + + "this info. Your pet info is safe with us :) \n"); + } + + public String getNameOfPet() { + Scanner input = new Scanner(System.in); + System.out.println("What is it's name?"); + return input.nextLine(); + } + + public String getTypeOfPet() { + Scanner input = new Scanner(System.in); + System.out.println("What kind of pet is it?"); + return input.nextLine(); + } + + public Integer howManyPetsYouGotDamn() { + Scanner input = new Scanner(System.in); + System.out.println("How many pets do you have?\n\nEnter the amount of pets: "); + return input.nextInt(); + + } + + public ArrayList fillList(String nameOfPet, String typeOfPet) { + petList.add(new Pet()); + return petList; + } + + + public static ArrayList sortList(ArrayList petList) { + Collections.sort(petList, (Pet petOne, Pet petTwo)-> petOne.getName().compareTo(petTwo.getName())); + return petList; + + } + + + } + + diff --git a/src/main/java/io/zipcoder/Cat.java b/src/main/java/io/zipcoder/Cat.java new file mode 100644 index 0000000..6063f1d --- /dev/null +++ b/src/main/java/io/zipcoder/Cat.java @@ -0,0 +1,27 @@ +package io.zipcoder; + +public class Cat extends Pet implements Animal{ + private String name; + private Cat cat; + + public Cat() { + this.name = ""; + } + + public Cat(String name){ + this.name = name; + } + + public String getName() { + return name; + } + + public String speak() { + Animal cat = new Animal() { + public String speak() { + return "Meow (ever so softly)"; + } + }; + return cat.speak(); + } +} diff --git a/src/main/java/io/zipcoder/ComparePets.java b/src/main/java/io/zipcoder/ComparePets.java new file mode 100644 index 0000000..ce0ba3d --- /dev/null +++ b/src/main/java/io/zipcoder/ComparePets.java @@ -0,0 +1,9 @@ +package io.zipcoder; + +import java.util.Comparator; + +public class ComparePets implements Comparator { + public int compare(Pet p1, Pet p2) { + return p1.getName().compareTo(p2.getName()); + } +} diff --git a/src/main/java/io/zipcoder/Dog.java b/src/main/java/io/zipcoder/Dog.java new file mode 100644 index 0000000..93d16bd --- /dev/null +++ b/src/main/java/io/zipcoder/Dog.java @@ -0,0 +1,27 @@ +package io.zipcoder; + +public class Dog extends Pet implements Animal{ + private String name; + private Dog dog; + + public Dog() { + this.name = ""; + } + + public Dog(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String speak() { + Animal dog = new Animal(){ + public String speak() { + return "Woof!"; + } + }; + return dog.speak(); + } +} diff --git a/src/main/java/io/zipcoder/ElectricMouse.java b/src/main/java/io/zipcoder/ElectricMouse.java new file mode 100644 index 0000000..e37607a --- /dev/null +++ b/src/main/java/io/zipcoder/ElectricMouse.java @@ -0,0 +1,28 @@ +package io.zipcoder; + +public class ElectricMouse extends Pet implements Animal{ + private String name; + private ElectricMouse electricMouse; + + public ElectricMouse() { + this.name = ""; + } + + public ElectricMouse(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String speak() { + Animal electricMouse = new Animal() { + public String speak() { + return "PIKACHUUUUUUUU!"; + } + }; + return electricMouse.speak(); + } +} diff --git a/src/main/java/io/zipcoder/Pet.java b/src/main/java/io/zipcoder/Pet.java new file mode 100644 index 0000000..d05c765 --- /dev/null +++ b/src/main/java/io/zipcoder/Pet.java @@ -0,0 +1,29 @@ +package io.zipcoder; + +public class Pet { + private String name; + private Dog dog; + private Cat cat; + private Turtle turtle; + private ElectricMouse electricMouse; + public String typeOfPet; + + public Pet(){ + this.name = ""; + this.typeOfPet = ""; + } + + public Pet(String name, String typeOfPet) { + this.name = name; + this.typeOfPet = typeOfPet; + } + + public String speak(){ + return "Meow (ever so softly)"; + } + + public String getName() { + return name; + } + +} diff --git a/src/main/java/io/zipcoder/Turtle.java b/src/main/java/io/zipcoder/Turtle.java new file mode 100644 index 0000000..0ade5a6 --- /dev/null +++ b/src/main/java/io/zipcoder/Turtle.java @@ -0,0 +1,28 @@ +package io.zipcoder; + +public class Turtle extends Pet implements Animal{ + private String name; + private Turtle turtle; + + public Turtle() { + this.name = ""; + } + + public Turtle(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + + public String speak() { + Animal turtle = new Animal() { + public String speak() { + return "WEEESNAW!"; + } + }; + return turtle.speak(); + } +} diff --git a/src/test/java/io/zipcoder/ApplicationTest.java b/src/test/java/io/zipcoder/ApplicationTest.java index b744df5..ca334d8 100644 --- a/src/test/java/io/zipcoder/ApplicationTest.java +++ b/src/test/java/io/zipcoder/ApplicationTest.java @@ -1,5 +1,149 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; + +/** + * created by Frankie on 02/26/18 + */ public class ApplicationTest { + Application application = new Application(); + ArrayList petList = new ArrayList<>(); + + /** + * All tests below contain methods that can be called from a single operation() method. For example, + + public void operation(){ + welcomeUser(); + String type = getTypeOfPet(); + String name = getNameOfPet(); + ArrayList petList = fillList(type, name); + sortedList(petList); + } + + */ + + @Test + public void welcomeUserTest() { + + //This part is just setting the outputStream object to whatever is set in the method inside the application class + //For example, if System.out.println("Hello"); then outputStream is equal to "Hello" + //Thus, a unit test will make sure String expected = "Hello"; is equal to outputStream + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outputStream)); + + //Calls the method welcomeUser() which takes in no argument and return type void + //Method just prints out the welcome message + application.welcomeUser(); + + //Expected Welcome Message + String expected = + "******************** WELCOME PET OWNER **********************\n" + + "We will be asking you a couple of questions about your pets.\n" + + "No need to worry. We won't be doing anything sketchy with\n" + + "this info. Your pet info is safe with us :) \n\n"; + //when putting it into the app class, take out the last "\n" + + //Comparison + Assert.assertEquals(expected, outputStream.toString()); + } + + @Test + public void howManyPetsYouGotDamnTest(){ + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outputStream)); + String in = "4"; + InputStream input = new ByteArrayInputStream(in.getBytes()); + System.setIn(input); + + Integer amountOfPets = application.howManyPetsYouGotDamn(); + + String expected = "How many pets do you have?\n\nEnter the amount of pets: \n"; + + Assert.assertEquals(expected, outputStream.toString()); + Assert.assertEquals(in, amountOfPets.toString()); + } + + + @Test + public void addPetInfoToListTestType1(){ + //This part is just setting the inputStream object to whatever is set in the scanner inside the method + //For example, if the inputStream = "hi" then Scanner.nextLine() = "hi"; + //Thus, a unit test will make sure String expected = "hi"; is equal to return type + String in = "Dog"; + InputStream input = new ByteArrayInputStream(in.getBytes()); + System.setIn(input); + + String actual = application.getTypeOfPet(); //method will be in the addPetInfoToList() method + + String expected = "Dog"; + + Assert.assertEquals(expected, actual); + } + + @Test + public void addPetInfoToListTestType2(){ + String in = "Cat"; + InputStream input = new ByteArrayInputStream(in.getBytes()); + System.setIn(input); + + String actual = application.getTypeOfPet(); //method will be in the addPetInfoToList() method + + String expected = "Cat"; + + Assert.assertEquals(expected, actual); + } + + + @Test + public void addPetInfoToListTestName(){ + String in = "Sally"; + InputStream input = new ByteArrayInputStream(in.getBytes()); + System.setIn(input); + + String actual = application.getNameOfPet(); + + String expected = "Sally"; + + Assert.assertEquals(actual, expected); + } + + @Test + public void fillList(){ + String type = "Cat"; + String name = "Sally"; + ArrayList petList = application.fillList(name, type);//fills the list with objects depending on the input + //three types: Cat, Dog, Turtle + + Assert.assertNotEquals(null, petList); + } + + @Test + public void sortList(){ + //just filling an array list + String type = "Cat"; + String name = "Sally"; + String type2 = "Dog"; + String name2 = "Bob"; + + application.fillList(name, type); + application.fillList(name2, type2); + + + //start of real test with sorting the created ArrayList + ArrayList petListSorted = Application.sortList(petList); + + //two tests to make sure ArrayList is not null and that the sorted list isn't equal to the original list + Assert.assertNotEquals(null, petListSorted); +// Assert.assertNotEquals(petList, petListSorted); + + + } } diff --git a/src/test/java/io/zipcoder/CatTest.java b/src/test/java/io/zipcoder/CatTest.java new file mode 100644 index 0000000..c801c6d --- /dev/null +++ b/src/test/java/io/zipcoder/CatTest.java @@ -0,0 +1,58 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * created by Frankie on 02/26/18 + */ +public class CatTest { + Cat cat; + + /** + * the Cat class should extend the Pet class + * Should feature a null constructor that defaults name = ""; + * and feature a name constructor that sets this.name = name; + */ + + @Before + public void instantiateCat() { + String name = "Bob"; + cat = new Cat(name); + } + + @Test + public void speakTest() { + String response = cat.speak(); + String expected = "Meow (ever so softly)"; + Assert.assertEquals(expected, response); + /* looks something like: + public String speak() { + Animal cat = new Animal() { + @Override + public String speak() { + return "Meow"; + } + }; + return cat.speak(); + } + */ + } + + + @Test + public void getNameTest1(){ + String actual = cat.getName(); + String expected = "Bob"; + Assert.assertEquals(expected, actual); + } + + @Test + public void getNameTest2(){ + cat = new Cat(); + String actual = cat.getName(); + String expected = ""; + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/DogTest.java b/src/test/java/io/zipcoder/DogTest.java new file mode 100644 index 0000000..b21570f --- /dev/null +++ b/src/test/java/io/zipcoder/DogTest.java @@ -0,0 +1,57 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * created by Frankie on 02/26/18 + */ +public class DogTest { + Dog dog; + /** + * the dog class should extend the Pet class + * Should feature a null constructor that defaults name = ""; + * and feature a name constructor that sets this.name = name; + */ + + @Before + public void instantiateDog() { + String name = "April"; + dog = new Dog(name); + } + + @Test + public void speakTest() { + String response = dog.speak(); + String expected = "Woof!"; + Assert.assertEquals(expected, response); + /* looks something like: + public String speak() { + Animal dog = new Animal() { + @Override + public String speak() { + return "Meow"; + } + }; + return dog.speak(); + } + */ + } + + + @Test + public void getNameTest1(){ + String actual = dog.getName(); + String expected = "April"; + Assert.assertEquals(expected, actual); + } + + @Test + public void getNameTest2(){ + dog = new Dog(); + String actual = dog.getName(); + String expected = ""; + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/ElectricMouseTest.java b/src/test/java/io/zipcoder/ElectricMouseTest.java new file mode 100644 index 0000000..4c41a45 --- /dev/null +++ b/src/test/java/io/zipcoder/ElectricMouseTest.java @@ -0,0 +1,54 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ElectricMouseTest { + ElectricMouse electricMouse; + /** + * the electricMouse class should extend the Pet class + * Should feature a null constructor that defaults name = ""; + * and feature a name constructor that sets this.name = name; + */ + + @Before + public void instantiateElectricMouse() { + String name = "Pikachu"; + electricMouse = new ElectricMouse(name); + } + + @Test + public void speakTest() { + String response = electricMouse.speak(); + String expected = "PIKACHUUUUUUUU!"; + Assert.assertEquals(expected, response); + /* looks something like: + public String speak() { + Animal electricMouse = new Animal() { + @Override + public String speak() { + return "Meow"; + } + }; + return electricMouse.speak(); + } + */ + } + + + @Test + public void getNameTest1(){ + String actual = electricMouse.getName(); + String expected = "Pikachu"; + Assert.assertEquals(expected, actual); + } + + @Test + public void getNameTest2(){ + electricMouse = new ElectricMouse(); + String actual = electricMouse.getName(); + String expected = ""; + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/PetTest.java b/src/test/java/io/zipcoder/PetTest.java new file mode 100644 index 0000000..aa248f2 --- /dev/null +++ b/src/test/java/io/zipcoder/PetTest.java @@ -0,0 +1,53 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + +/** + * created by Frankie on 02/26/18 + */ +public class PetTest { + + /** + * the pet class should be abstract and implement the Animal interface + * + * Should feature a null constructor that defaults name = ""; + * and feature a name constructor that sets this.name = name; + */ + Pet pet; + Dog dog; + Cat cat; + Turtle turtle; + ElectricMouse electricMouse; + + @Test + public void testInheritance() { + Pet p = new Dog(); + Assert.assertTrue(p instanceof Pet); + } + + @Test + public void testImplementation() { + Pet p = new Dog(); + Assert.assertTrue(p instanceof Animal); + } + + @Test + public void GetNameTest1(){ + String name = "Andy"; + pet = new Dog(name); + + String nameReturn = pet.getName(); + Assert.assertEquals(nameReturn, name); + } + + @Test + public void GetNameTest2(){ + String name = "Gloria"; + pet = new Dog(name); + + String nameReturn = pet.getName(); + Assert.assertEquals(nameReturn, name); + } + +} diff --git a/src/test/java/io/zipcoder/TestSuite.java b/src/test/java/io/zipcoder/TestSuite.java new file mode 100644 index 0000000..29f0319 --- /dev/null +++ b/src/test/java/io/zipcoder/TestSuite.java @@ -0,0 +1,17 @@ +package io.zipcoder; + + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ApplicationTest.class, + CatTest.class, + DogTest.class, + ElectricMouseTest.class, + PetTest.class, + TurtleTest.class +}) +public class TestSuite { +} diff --git a/src/test/java/io/zipcoder/TurtleTest.java b/src/test/java/io/zipcoder/TurtleTest.java new file mode 100644 index 0000000..9961da4 --- /dev/null +++ b/src/test/java/io/zipcoder/TurtleTest.java @@ -0,0 +1,57 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * created by Frankie on 02/26/18 + */ +public class TurtleTest { + Turtle turtle; + /** + * the turtle class should extend the Pet class + * Should feature a null constructor that defaults name = ""; + * and feature a name constructor that sets this.name = name; + */ + + @Before + public void instantiateTurtle() { + String name = "Crush"; + turtle = new Turtle(name); + } + + @Test + public void speakTest() { + String response = turtle.speak(); + String expected = "WEEESNAW!"; + Assert.assertEquals(expected, response); + /* looks something like: + public String speak() { + Animal turtle = new Animal() { + @Override + public String speak() { + return "Meow"; + } + }; + return turtle.speak(); + } + */ + } + + + @Test + public void getNameTest1(){ + String actual = turtle.getName(); + String expected = "Crush"; + Assert.assertEquals(expected, actual); + } + + @Test + public void getNameTest2(){ + turtle = new Turtle(); + String actual = turtle.getName(); + String expected = ""; + Assert.assertEquals(expected, actual); + } +}