Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba76ac8

Browse files
committed
Adds first blogpost example and junit 4 dependency in maven
1 parentefccc83 commitba76ac8

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+
packagecom.coderolls.SampleProject;
2+
3+
publicclassPasswordGenerator {
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+
publicStringgeneratePassword(Stringname,intyearOfBirth) {
18+
Stringpassword =null;
19+
20+
if(name ==null) {
21+
returnpassword;
22+
}
23+
24+
if(name.length()<=4) {
25+
password =name+yearOfBirth;
26+
}else {
27+
Stringstr =name.substring(0,4);
28+
password =str+yearOfBirth;
29+
}
30+
returnpassword;
31+
}
32+
33+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
packagecom.coderolls.SampleProject;
2+
3+
importorg.junit.Test;
4+
5+
importjunit.framework.TestCase;
6+
7+
publicclassPasswordGeneratorTestextendsTestCase {
8+
9+
@Test
10+
publicvoidtestGeneratePassword() {
11+
Stringname="Joseph";
12+
intyearOFBirth =1998;
13+
14+
Stringexpected ="Jose1998";
15+
16+
PasswordGeneratorpasswordGenerator =newPasswordGenerator();
17+
Stringactual =passwordGenerator.generatePassword(name,yearOFBirth);
18+
assertEquals(expected,actual);
19+
}
20+
21+
@Test
22+
publicvoidtestGeneratePassword_nameLessThan4Charaters() {
23+
Stringname="Nic";
24+
intyearOFBirth =2002;
25+
26+
Stringexpected ="Nic2002";
27+
28+
PasswordGeneratorpasswordGenerator =newPasswordGenerator();
29+
Stringactual =passwordGenerator.generatePassword(name,yearOFBirth);
30+
31+
assertEquals(expected,actual);
32+
}
33+
34+
@Test
35+
publicvoidtestGeneratePassword_nameIsNull() {
36+
Stringname=null;
37+
intyearOFBirth =2002;
38+
39+
PasswordGeneratorpasswordGenerator =newPasswordGenerator();
40+
Stringactual =passwordGenerator.generatePassword(name,yearOFBirth);
41+
42+
assertNull(actual);
43+
}
44+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp