Skip to content

Commit af95fe9

Browse files
Add files via upload
1 parent ec0440a commit af95fe9

File tree

24 files changed

+256
-0
lines changed

24 files changed

+256
-0
lines changed

javaprogs/Testing/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.cognixia</groupId>
4+
<artifactId>Testing</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<dependencies>
7+
<dependency>
8+
<groupId>junit</groupId>
9+
<artifactId>junit</artifactId>
10+
<version>4.12</version>
11+
<scope>test</scope>
12+
</dependency>
13+
14+
</dependencies>
15+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.cognixia;
2+
3+
import org.junit.runner.RunWith;
4+
import org.junit.runners.Suite;
5+
import org.junit.runners.Suite.SuiteClasses;
6+
7+
@RunWith(Suite.class)
8+
@SuiteClasses({ unitest.class, unitest2.class })
9+
public class AllTests {
10+
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.cognixia;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
public class unitest {
10+
11+
12+
@Test
13+
public void test() {
14+
int actual=1;
15+
int exepected=1;
16+
17+
assertEquals(actual,exepected);
18+
}
19+
20+
@Test
21+
public void test1() {
22+
int actual=1;
23+
int exepected=2;
24+
25+
assertEquals(actual,exepected);
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.cognixia;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
public class unitest2 {
10+
11+
12+
13+
@Test
14+
public void test() {
15+
int actual=1;
16+
int exepected=1;
17+
18+
assertEquals(actual,exepected);
19+
}
20+
21+
@Test
22+
public void test1() {
23+
int actual=1;
24+
int exepected=2;
25+
26+
assertEquals(actual,exepected);
27+
}
28+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Manifest-Version: 1.0
2+
Built-By: raman
3+
Build-Jdk: 11.0.10
4+
Created-By: Maven Integration for Eclipse
5+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Generated by Maven Integration for Eclipse
2+
#Sat Mar 06 12:14:34 IST 2021
3+
m2e.projectLocation=E\:\\javaprogs\\Testing
4+
m2e.projectName=Testing
5+
groupId=com.cognixia
6+
artifactId=Testing
7+
version=0.0.1-SNAPSHOT
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.cognixia</groupId>
4+
<artifactId>Testing</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<dependencies>
7+
<dependency>
8+
<groupId>junit</groupId>
9+
<artifactId>junit</artifactId>
10+
<version>4.12</version>
11+
<scope>test</scope>
12+
</dependency>
13+
14+
</dependencies>
15+
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.

javaprogs/mockito-example/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.raman</groupId>
4+
<artifactId>mockito-example</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<dependencies>
7+
<dependency>
8+
<groupId>junit</groupId>
9+
<artifactId>junit</artifactId>
10+
<version>4.12</version>
11+
<scope>test</scope>
12+
</dependency>
13+
<dependency>
14+
<groupId>org.mockito</groupId>
15+
<artifactId>mockito-all</artifactId>
16+
<version>1.10.19</version>
17+
<scope>test</scope>
18+
</dependency>
19+
</dependencies>
20+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.raman.business;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.raman.data.api.TodoService;
7+
8+
public class TodoBusinessImpl {
9+
private TodoService todoService;
10+
11+
TodoBusinessImpl(TodoService todoService) {
12+
this.todoService = todoService;
13+
}
14+
15+
public List<String> retrieveTodosRelatedToSpring(String user) {
16+
List<String> filteredTodos = new ArrayList<String>();
17+
List<String> allTodos = todoService.retrieveTodos(user);
18+
for (String todo : allTodos) {
19+
if (todo.contains("Spring")) {
20+
filteredTodos.add(todo);
21+
}
22+
}
23+
return filteredTodos;
24+
}
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.raman.data.api;
2+
3+
import java.util.List;
4+
5+
public interface TodoService {
6+
public List<String> retrieveTodos(String user);
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.raman;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.Test;
6+
7+
public class FirstTest {
8+
9+
@Test
10+
public void test() {
11+
assertTrue(true);
12+
}
13+
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.raman.business;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.when;
6+
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
import org.junit.Test;
11+
12+
import com.raman.data.api.TodoService;
13+
import com.raman.data.stub.TodoServiceStub;
14+
15+
public class TodoBusinessImplStubTest {
16+
17+
@Test
18+
public void test() {
19+
TodoService todoService = new TodoServiceStub();
20+
TodoBusinessImpl todoBusinessImpl = new TodoBusinessImpl(todoService);
21+
List<String> todos = todoBusinessImpl
22+
.retrieveTodosRelatedToSpring("dummy");
23+
assertEquals(2, todos.size());
24+
}
25+
@Test
26+
public void usingMockito() {
27+
TodoService todoService = mock(TodoService.class);
28+
List<String> allTodos = Arrays.asList("Learn Spring MVC",
29+
"Learn Spring", "Learn to Dance");
30+
when(todoService.retrieveTodos("dummy")).thenReturn(allTodos);
31+
TodoBusinessImpl todoBusinessImpl = new TodoBusinessImpl(todoService);
32+
List<String> todos = todoBusinessImpl
33+
.retrieveTodosRelatedToSpring("dummy");
34+
assertEquals(2, todos.size());
35+
}
36+
37+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.raman.data.stub;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import com.raman.data.api.TodoService;
7+
8+
public class TodoServiceStub implements TodoService {
9+
public List<String> retrieveTodos(String user) {
10+
return Arrays.asList("Learn Spring MVC", "Learn Spring",
11+
"Learn to Dance");
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Manifest-Version: 1.0
2+
Built-By: raman
3+
Build-Jdk: 11.0.10
4+
Created-By: Maven Integration for Eclipse
5+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Generated by Maven Integration for Eclipse
2+
#Fri Mar 05 21:01:59 IST 2021
3+
m2e.projectLocation=E\:\\javaprogs\\mockito-example
4+
m2e.projectName=mockito-example
5+
groupId=com.raman
6+
artifactId=mockito-example
7+
version=0.0.1-SNAPSHOT
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.raman</groupId>
4+
<artifactId>mockito-example</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<dependencies>
7+
<dependency>
8+
<groupId>junit</groupId>
9+
<artifactId>junit</artifactId>
10+
<version>4.12</version>
11+
<scope>test</scope>
12+
</dependency>
13+
<dependency>
14+
<groupId>org.mockito</groupId>
15+
<artifactId>mockito-all</artifactId>
16+
<version>1.10.19</version>
17+
<scope>test</scope>
18+
</dependency>
19+
</dependencies>
20+
</project>
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)