Last active
December 21, 2015 08:58
-
-
Save tiennv90/6281581 to your computer and use it in GitHub Desktop.
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
package com.nextuser.evaluation; | |
import java.sql.SQLException; | |
import java.util.List; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mock; | |
import org.powermock.modules.junit4.legacy.PowerMockRunner; | |
import com.nextuser.model.ConnectionType; | |
import com.nextuser.model.Rule; | |
import com.nextuser.model.RuleGroup; | |
import com.nextuser.model.Website; | |
import com.nextuser.model.Workflow; | |
import com.nextuser.model.WorkflowFrequency; | |
import com.nextuser.model.WorkflowItem; | |
import com.nextuser.model.WorkflowType; | |
import com.nextuser.model.dao.AbstractPostGreDAOMocker; | |
import static org.powermock.api.mockito.PowerMockito.when; | |
import static org.mockito.Mockito.*; | |
@RunWith(PowerMockRunner.class) | |
public class AbstractWorkflowEvaluationTest extends AbstractPostGreDAOMocker { | |
@Override | |
public AbstractPostGreDAOMocker setUpMockData() | |
throws NumberFormatException, SQLException { | |
return null; | |
} | |
@Override | |
public AbstractPostGreDAOMocker initResultSet() throws SQLException { | |
return null; | |
} | |
public Website setUpWebsite(int id, String code) { | |
Website website = mock(Website.class); | |
when(website.getId()).thenReturn(id); | |
when(website.getCode()).thenReturn(code); | |
return website; | |
} | |
public Workflow setUpWorkflow(int id, String name, String type, String freq, String description) { | |
Workflow workflow = mock(Workflow.class); | |
when(workflow.getId()).thenReturn(id); | |
when(workflow.getName()).thenReturn(name); | |
when(workflow.getFrequency()).thenReturn(WorkflowFrequency.getEnum(freq)); | |
when(workflow.getWorkflowType()).thenReturn(WorkflowType.getEnum(type)); | |
return workflow; | |
} | |
public WorkflowItem addConditionItem(Workflow w) { | |
WorkflowItem item = null; | |
if (isMockObject(w)) { | |
item = mock(WorkflowItem.class); | |
when(w.getListWorkflowItem().get(anyInt())).thenReturn(item); | |
//return 2 right connections | |
when(item.getRightConnectionsCount()).thenReturn(2); | |
//one true | |
when(item.getRightConnections().get(0).getType()).thenReturn(ConnectionType.TRUE); | |
//one false | |
when(item.getRightConnections().get(1).getType()).thenReturn(ConnectionType.FALSE); | |
} | |
return item; | |
} | |
public RuleGroup addRuleGroup(WorkflowItem item) { | |
RuleGroup group = null; | |
if (isMockObject(item)) { | |
group = mock(RuleGroup.class); | |
when(item.getListRuleGroup().get(anyInt())).thenReturn(group); | |
} | |
return group; | |
} | |
public Rule addRule(RuleGroup group) { | |
Rule rule = null; | |
if (isMockObject(group)) { | |
rule = mock(Rule.class); | |
when(group.getListRule().get(anyInt())).thenReturn(rule); | |
} | |
return rule; | |
} | |
public static boolean isMockObject(Object obj) { | |
if (obj.getClass().getName().contains("EnhancerByMockitoWithCGLIB")) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment