Skip to content

Commit ba76ac8

Browse files
committed
Adds first blogpost example and junit 4 dependency in maven
1 parent efccc83 commit ba76ac8

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# junit-tutorial
2-
A repository for JUnit tutorial example
1+
# JUnit Tutorial
2+
3+
A repository for JUnit Tutorial examples from the blog and videos
4+
5+
1. [Why We Write JUnit Test Cases?](https://coderolls.com/why-unit-test-cases/)
6+
2. [How To Write JUnit Test Case In Java? (With Example)](https://coderolls.com/junit-test-case-in-java/)

pom.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
</properties>
1616

1717
<dependencies>
18-
<dependency>
19-
<groupId>junit</groupId>
20-
<artifactId>junit</artifactId>
21-
<version>3.8.1</version>
22-
<scope>test</scope>
23-
</dependency>
18+
<!-- https://mvnrepository.com/artifact/junit/junit -->
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.0</version>
23+
<scope>test</scope>
24+
</dependency>
25+
2426
</dependencies>
2527
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.coderolls.SampleProject;
2+
3+
public class PasswordGenerator {
4+
/**
5+
* A method generate password from name and year of birth
6+
*
7+
* Ex. For name 'Thomas' and Year of birth '1992', it will generate password as 'Thom1992'.
8+
*
9+
* If name has equal to or less than 4 character then it will return name+YearOfith as password.
10+
*
11+
* Ex. For name 'Mary' and year of birth '2003', it will return 'Mary2003' as password.
12+
*
13+
* @param name
14+
* @param yearOfBirth
15+
* @return
16+
*/
17+
public String generatePassword(String name, int yearOfBirth) {
18+
String password = null;
19+
20+
if(name ==null) {
21+
return password;
22+
}
23+
24+
if(name.length()<=4) {
25+
password = name+yearOfBirth;
26+
}else {
27+
String str = name.substring(0, 4);
28+
password =str+yearOfBirth;
29+
}
30+
return password;
31+
}
32+
33+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.coderolls.SampleProject;
2+
3+
import org.junit.Test;
4+
5+
import junit.framework.TestCase;
6+
7+
public class PasswordGeneratorTest extends TestCase {
8+
9+
@Test
10+
public void testGeneratePassword() {
11+
String name= "Joseph";
12+
int yearOFBirth = 1998;
13+
14+
String expected = "Jose1998";
15+
16+
PasswordGenerator passwordGenerator = new PasswordGenerator();
17+
String actual = passwordGenerator.generatePassword(name, yearOFBirth);
18+
assertEquals(expected, actual);
19+
}
20+
21+
@Test
22+
public void testGeneratePassword_nameLessThan4Charaters() {
23+
String name= "Nic";
24+
int yearOFBirth = 2002;
25+
26+
String expected = "Nic2002";
27+
28+
PasswordGenerator passwordGenerator = new PasswordGenerator();
29+
String actual = passwordGenerator.generatePassword(name, yearOFBirth);
30+
31+
assertEquals(expected, actual);
32+
}
33+
34+
@Test
35+
public void testGeneratePassword_nameIsNull() {
36+
String name= null;
37+
int yearOFBirth = 2002;
38+
39+
PasswordGenerator passwordGenerator = new PasswordGenerator();
40+
String actual = passwordGenerator.generatePassword(name, yearOFBirth);
41+
42+
assertNull(actual);
43+
}
44+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy