BAEL-19988: Migrate mocks module to the com.baeldung package
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.jmockit;
|
||||
|
||||
public class AdvancedCollaborator {
|
||||
int i;
|
||||
private int privateField = 5;
|
||||
public AdvancedCollaborator(){}
|
||||
public AdvancedCollaborator(String string) throws Exception{
|
||||
i = string.length();
|
||||
}
|
||||
public String methodThatCallsPrivateMethod(int i){
|
||||
return privateMethod() + i;
|
||||
}
|
||||
public int methodThatReturnsThePrivateField(){
|
||||
return privateField;
|
||||
}
|
||||
private String privateMethod(){
|
||||
return "default:";
|
||||
}
|
||||
class InnerAdvancedCollaborator{}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.mocks.jmockit;
|
||||
package com.baeldung.jmockit;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.jmockit;
|
||||
|
||||
public class Collaborator {
|
||||
|
||||
public boolean collaborate(String string){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void receive(boolean bool){
|
||||
//NOOP
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.jmockit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExpectationsCollaborator {
|
||||
String methodForAny1(String s, int i, Boolean b);
|
||||
void methodForAny2(Long l, List<String> lst);
|
||||
String methodForWith1(String s, int i);
|
||||
void methodForWith2(Boolean b, List<String> l);
|
||||
String methodForNulls1(String s, List<String> l);
|
||||
void methodForNulls2(String s, List<String> l);
|
||||
void methodForTimes1();
|
||||
void methodForTimes2();
|
||||
void methodForTimes3();
|
||||
void methodForArgThat(Object o);
|
||||
String methodReturnsString();
|
||||
int methodReturnsInt();
|
||||
Object methodForDelegate(int i);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.jmockit;
|
||||
|
||||
public class Model {
|
||||
public String getInfo() {
|
||||
return "info";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.jmockit;
|
||||
|
||||
public class Performer {
|
||||
private Collaborator collaborator;
|
||||
|
||||
public void perform(Model model){
|
||||
boolean value = collaborator.collaborate(model.getInfo());
|
||||
collaborator.receive(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.testCase;
|
||||
|
||||
public class LoginController {
|
||||
|
||||
public LoginService loginService;
|
||||
|
||||
public String login(UserForm userForm) {
|
||||
if (null == userForm) {
|
||||
return "ERROR";
|
||||
} else {
|
||||
boolean logged;
|
||||
|
||||
try {
|
||||
logged = loginService.login(userForm);
|
||||
} catch (Exception e) {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
if (logged) {
|
||||
loginService.setCurrentUser(userForm.getUsername());
|
||||
return "OK";
|
||||
} else {
|
||||
return "KO";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// standard setters and getters
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.testCase;
|
||||
|
||||
public class LoginDao {
|
||||
|
||||
public int login(UserForm userForm) {
|
||||
//actual call to a third party library
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.testCase;
|
||||
|
||||
public class LoginService {
|
||||
|
||||
private LoginDao loginDao;
|
||||
|
||||
private String currentUser;
|
||||
|
||||
public boolean login(UserForm userForm) {
|
||||
assert null != userForm;
|
||||
|
||||
int loginResults = loginDao.login(userForm);
|
||||
|
||||
switch (loginResults) {
|
||||
case 1:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentUser(String username) {
|
||||
if (null != username) {
|
||||
this.currentUser = username;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLoginDao(LoginDao loginDao) {
|
||||
this.loginDao = loginDao;
|
||||
}
|
||||
|
||||
// standard setters and getters
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.testCase;
|
||||
|
||||
public class UserForm {
|
||||
|
||||
// public access modifiers as only for testing
|
||||
|
||||
public String password;
|
||||
|
||||
public String username;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user