From 1e5cac16444919432196f5f82c2fb6a6913a3869 Mon Sep 17 00:00:00 2001 From: mondira-roy2020 Date: Mon, 20 Jul 2020 11:00:09 -0400 Subject: [PATCH 1/2] Person class created --- pom.xml | 6 +++++ .../github/curriculeon/MainApplication.java | 7 ++++++ .../java/com/github/curriculeon/Person.java | 22 +++++++++++++++++++ .../java/groovy/util/GroovyTestCase.groovy | 4 ++++ .../com/github/curriculeon/PersonTest.groovy | 16 ++++++++++++++ .../com/github/curriculeon/TestPerson.java | 5 ----- 6 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/github/curriculeon/MainApplication.java create mode 100644 src/main/java/groovy/util/GroovyTestCase.groovy create mode 100644 src/test/java/com/github/curriculeon/PersonTest.groovy delete mode 100644 src/test/java/com/github/curriculeon/TestPerson.java diff --git a/pom.xml b/pom.xml index aa0b434..663507d 100644 --- a/pom.xml +++ b/pom.xml @@ -27,5 +27,11 @@ 4.12 test + + org.testng + testng + RELEASE + test + diff --git a/src/main/java/com/github/curriculeon/MainApplication.java b/src/main/java/com/github/curriculeon/MainApplication.java new file mode 100644 index 0000000..1d70eb4 --- /dev/null +++ b/src/main/java/com/github/curriculeon/MainApplication.java @@ -0,0 +1,7 @@ +package com.github.curriculeon; + +public class MainApplication { + public static void main(String[] args) { + + } +} diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 3c8350b..29a80bf 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,5 +1,27 @@ package com.github.curriculeon; public class Person { +final long id; +private String name; + public Person() { + id = 0; + } + + public Person(long id, String name) { + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/src/main/java/groovy/util/GroovyTestCase.groovy b/src/main/java/groovy/util/GroovyTestCase.groovy new file mode 100644 index 0000000..e1b6eff --- /dev/null +++ b/src/main/java/groovy/util/GroovyTestCase.groovy @@ -0,0 +1,4 @@ +package groovy.util + +class GroovyTestCase { +} diff --git a/src/test/java/com/github/curriculeon/PersonTest.groovy b/src/test/java/com/github/curriculeon/PersonTest.groovy new file mode 100644 index 0000000..95dc97b --- /dev/null +++ b/src/test/java/com/github/curriculeon/PersonTest.groovy @@ -0,0 +1,16 @@ +package com.github.curriculeon + +class PersonTest extends GroovyTestCase { + void setUp() { + super.setUp() + } + + void testGetId() { + } + + void testGetName() { + } + + void testSetName() { + } +} diff --git a/src/test/java/com/github/curriculeon/TestPerson.java b/src/test/java/com/github/curriculeon/TestPerson.java deleted file mode 100644 index 6c523fe..0000000 --- a/src/test/java/com/github/curriculeon/TestPerson.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.curriculeon; - -public class TestPerson { - -} From d079d120b096ce92edfc88be23861f232386ee72 Mon Sep 17 00:00:00 2001 From: mondira-roy2020 Date: Mon, 20 Jul 2020 16:34:44 -0400 Subject: [PATCH 2/2] Writing tests from scratch --- .../java/com/github/curriculeon/Person.java | 10 ++---- .../java/groovy/util/GroovyTestCase.groovy | 4 --- src/test/java/PersonTest.java | 36 +++++++++++++++++++ .../com/github/curriculeon/PersonTest.groovy | 16 --------- 4 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/groovy/util/GroovyTestCase.groovy create mode 100644 src/test/java/PersonTest.java delete mode 100644 src/test/java/com/github/curriculeon/PersonTest.groovy diff --git a/src/main/java/com/github/curriculeon/Person.java b/src/main/java/com/github/curriculeon/Person.java index 29a80bf..f8ab018 100644 --- a/src/main/java/com/github/curriculeon/Person.java +++ b/src/main/java/com/github/curriculeon/Person.java @@ -1,19 +1,15 @@ package com.github.curriculeon; public class Person { -final long id; +private final Long id; private String name; - public Person() { - id = 0; - } - - public Person(long id, String name) { + public Person(Long id, String name) { this.id = id; this.name = name; } - public long getId() { + public Long getId() { return id; } diff --git a/src/main/java/groovy/util/GroovyTestCase.groovy b/src/main/java/groovy/util/GroovyTestCase.groovy deleted file mode 100644 index e1b6eff..0000000 --- a/src/main/java/groovy/util/GroovyTestCase.groovy +++ /dev/null @@ -1,4 +0,0 @@ -package groovy.util - -class GroovyTestCase { -} diff --git a/src/test/java/PersonTest.java b/src/test/java/PersonTest.java new file mode 100644 index 0000000..fe06958 --- /dev/null +++ b/src/test/java/PersonTest.java @@ -0,0 +1,36 @@ +import com.github.curriculeon.Person; +import org.junit.Assert; +import org.junit.Test; +import sun.management.snmp.jvminstr.JvmThreadInstanceEntryImpl; + +public class PersonTest { + @Test + public void testConstructor() { + //Given + Long expectedId = 0L; + String expectedName = "Some Name;"; + //When + Person person = new Person(expectedId,expectedName); + Long actualId = person.getId(); + String actualName = person.getName(); + //Then + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName); + + } + @Test + public void testSetName(){ + //Given + Person person = new Person(null,null); + String expectedName = "Some Name"; + Assert.assertNotEquals(expectedName,person.getName()); + + //When + person.setName(expectedName); + String actualName = person.getName(); + + //Then + Assert.assertEquals(expectedName, actualName); + } + +} diff --git a/src/test/java/com/github/curriculeon/PersonTest.groovy b/src/test/java/com/github/curriculeon/PersonTest.groovy deleted file mode 100644 index 95dc97b..0000000 --- a/src/test/java/com/github/curriculeon/PersonTest.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.curriculeon - -class PersonTest extends GroovyTestCase { - void setUp() { - super.setUp() - } - - void testGetId() { - } - - void testGetName() { - } - - void testSetName() { - } -}