-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inited basic project structure for Mockito practice.
- Loading branch information
Showing
8 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
group 'javamockito' | ||
version '1.0-SNAPSHOT' | ||
|
||
apply plugin: 'java' | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testCompile group: 'junit', name: 'junit', version: '4.12' | ||
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.4' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rootProject.name = 'javamockito' | ||
|
13 changes: 13 additions & 0 deletions
13
JustPractice/java/javamockito/src/main/org/mewx/practice/javamockito/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.mewx.practice.javamockito; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
ArrayList<String> input = new ArrayList<>(); | ||
input.add("One message"); | ||
|
||
Message messageHost = new Message(); | ||
new ServiceCaller().callService(input, messageHost); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
JustPractice/java/javamockito/src/main/org/mewx/practice/javamockito/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.mewx.practice.javamockito; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Message { | ||
private ArrayList<String> messages = new ArrayList<>(); | ||
|
||
public void addMessage(String msg) { | ||
messages.add(msg); | ||
} | ||
|
||
public int getSize() { | ||
return messages.size(); | ||
} | ||
|
||
public String getMessageAt(int idx) { | ||
return idx < messages.size() ? messages.get(idx) : null; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
JustPractice/java/javamockito/src/main/org/mewx/practice/javamockito/Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.mewx.practice.javamockito; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* The supposed rule is when the size of the list is less than 2, add a message to message | ||
*/ | ||
public class Service { | ||
static final String ERROR_MSG = "This is an error message"; | ||
|
||
public void runService(List<String> list, Message message) { | ||
final int THRESHOLD = 2; | ||
if (list.size() < THRESHOLD) { | ||
message.addMessage(ERROR_MSG); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
JustPractice/java/javamockito/src/main/org/mewx/practice/javamockito/ServiceCaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.mewx.practice.javamockito; | ||
|
||
import java.util.List; | ||
|
||
public class ServiceCaller { | ||
public void callService(List<String> list, Message messageHost) { | ||
new Service().runService(list, messageHost); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
JustPractice/java/javamockito/src/test/org/mewx/practice/javamockito/MessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.mewx.practice.javamockito; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class MessageTest { | ||
private Message message; | ||
|
||
@Before | ||
public void setUp() { | ||
message = new Message(); | ||
} | ||
|
||
@Test | ||
public void addMessage() { | ||
assertEquals(0, message.getSize()); | ||
message.addMessage("new message"); | ||
assertEquals(1, message.getSize()); | ||
} | ||
|
||
@Test | ||
public void getMessageAt() { | ||
final String NEW_MSG = "new message"; | ||
assertEquals(null, message.getMessageAt(0)); | ||
message.addMessage(NEW_MSG); | ||
assertEquals(NEW_MSG, message.getMessageAt(0)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
JustPractice/java/javamockito/src/test/org/mewx/practice/javamockito/ServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.mewx.practice.javamockito; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ServiceTest { | ||
private Service service; | ||
private Message message; | ||
private ArrayList<String> list; | ||
|
||
@Before | ||
public void setUp() { | ||
service = new Service(); | ||
message = new Message(); | ||
list = new ArrayList<>(); | ||
} | ||
|
||
@Test | ||
public void runServiceWithNoneInList() { | ||
service.runService(list, message); | ||
assertEquals(1, message.getSize()); | ||
assertEquals(Service.ERROR_MSG, message.getMessageAt(0)); | ||
} | ||
|
||
@Test | ||
public void runServiceWithOneInList() { | ||
list.add("One"); | ||
|
||
service.runService(list, message); | ||
assertEquals(1, message.getSize()); | ||
assertEquals(Service.ERROR_MSG, message.getMessageAt(0)); | ||
} | ||
|
||
@Test | ||
public void runServiceWithTwoInList() { | ||
list.add("One"); | ||
list.add("Two"); | ||
|
||
service.runService(list, message); | ||
assertEquals(0, message.getSize()); | ||
} | ||
} |