|
@@ -0,0 +1,65 @@
|
|
|
+package com.mooctest.crowd.domain.mediator.impl;
|
|
|
+
|
|
|
+import com.mooctest.crowd.domain.command.LoginCommand;
|
|
|
+import com.mooctest.crowd.domain.command.RegisterCommand;
|
|
|
+import com.mooctest.crowd.domain.domainobject.Account;
|
|
|
+import com.mooctest.crowd.domain.exception.PasswordErrorException;
|
|
|
+import com.mooctest.crowd.domain.factory.AccountFactory;
|
|
|
+import com.mooctest.crowd.domain.mediator.Mediator;
|
|
|
+import com.mooctest.crowd.domain.service.RegisterService;
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.mockito.Mock;
|
|
|
+import org.powermock.api.mockito.PowerMockito;
|
|
|
+import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
+import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
+
|
|
|
+import static org.junit.Assert.*;
|
|
|
+import static org.mockito.Matchers.any;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: xuexb
|
|
|
+ * @Date: 2019.7.16 20:39
|
|
|
+ */
|
|
|
+@RunWith(PowerMockRunner.class)
|
|
|
+@PrepareForTest(AccountFactory.class)
|
|
|
+public class WebMediatorImplTest {
|
|
|
+
|
|
|
+
|
|
|
+ private Mediator mediator;
|
|
|
+ private Account account;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void setUp(){
|
|
|
+ account = new Account();
|
|
|
+ account.setPassword("CORRECT_PWD");
|
|
|
+ account.setMobileNum("EXiSTS_MOBILE");
|
|
|
+
|
|
|
+ mediator = new WebMediatorImpl();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_true_when_login_success() throws PasswordErrorException {
|
|
|
+ //arrange
|
|
|
+ PowerMockito.mockStatic(AccountFactory.class);
|
|
|
+ PowerMockito.when(AccountFactory.createAccount()).thenReturn(account);
|
|
|
+ LoginCommand cmd = new LoginCommand("EXiSTS_MOBILE", "CORRECT_PWD", "CODE");
|
|
|
+ //action
|
|
|
+ boolean success = mediator.login(cmd);
|
|
|
+ //assert
|
|
|
+ assertTrue(success);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_account_when_register_success() {
|
|
|
+ //arrange
|
|
|
+ RegisterCommand cmd = new RegisterCommand("NEW_MOBILE","CODE","PWD");
|
|
|
+
|
|
|
+ //action
|
|
|
+ Account newAccount = RegisterService.register(cmd);
|
|
|
+
|
|
|
+ //assert
|
|
|
+ assertEquals("NEW_MOBILE", newAccount.getMobileNum());
|
|
|
+ }
|
|
|
+}
|