Browse Source

提交单元测试,防止空指针

feature/big-screen
Maksim 5 years ago
parent
commit
e544673a4d
  1. 7
      designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java
  2. 52
      designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java
  3. 19
      designer-base/src/test/java/com/fr/design/write/submit/CheckServiceDialogTest.java

7
designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java

@ -27,6 +27,7 @@ import com.fr.log.FineLoggerFactory;
import com.fr.rpc.Result; import com.fr.rpc.Result;
import com.fr.stable.AssistUtils; import com.fr.stable.AssistUtils;
import com.fr.stable.EnvChangedListener; import com.fr.stable.EnvChangedListener;
import com.fr.stable.StringUtils;
import com.fr.start.server.ServerTray; import com.fr.start.server.ServerTray;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.WorkContextCallback; import com.fr.workspace.WorkContextCallback;
@ -38,6 +39,7 @@ import com.fr.workspace.engine.channel.http.FunctionalHttpRequest;
import com.fr.workspace.engine.exception.WorkspaceAuthException; import com.fr.workspace.engine.exception.WorkspaceAuthException;
import com.fr.workspace.engine.exception.WorkspaceConnectionException; import com.fr.workspace.engine.exception.WorkspaceConnectionException;
import com.fr.workspace.engine.rpc.WorkspaceProxyPool; import com.fr.workspace.engine.rpc.WorkspaceProxyPool;
import jdk.nashorn.internal.objects.annotations.Function;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -262,6 +264,9 @@ public class EnvChangeEntrance {
try { try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
if(StringUtils.isEmpty(selectedEnv.getRemindTime())){
return true;
}
//获取记录的时间 //获取记录的时间
Date remindTime = format.parse(selectedEnv.getRemindTime()); Date remindTime = format.parse(selectedEnv.getRemindTime());
calendar.setTime(remindTime); calendar.setTime(remindTime);
@ -325,7 +330,7 @@ public class EnvChangeEntrance {
return noExistServiceSet; return noExistServiceSet;
} catch (Exception e){ } catch (Exception e){
FineLoggerFactory.getLogger().error(e.getMessage(),e); FineLoggerFactory.getLogger().error(e.getMessage(),e);
return null; return noExistServiceSet;
} }
} }

52
designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java

@ -0,0 +1,52 @@
package com.fr.design;
import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.DesignerWorkspaceType;
import com.fr.design.write.submit.CheckServiceDialog;
import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.channel.http.FunctionalHttpRequest;
import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* @author: Maksim
* @Date: Created in 2020/3/5
* @Description:
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({FunctionalHttpRequest.class,EnvChangeEntrance.class,CheckServiceDialog.class})
public class EnvChangeEntranceTest {
@Test
public void showServiceDialog() throws Exception {
EnvChangeEntrance entrance = EnvChangeEntrance.getInstance();
DesignerWorkspaceInfo selectedEnv = EasyMock.mock(DesignerWorkspaceInfo.class);
WorkspaceConnectionInfo connectionInfo = EasyMock.mock(WorkspaceConnectionInfo.class);
String remoteBranch = "Build#persist-2020.02.15.01.01.12.12";
EasyMock.expect(selectedEnv.getConnection()).andReturn(connectionInfo);
EasyMock.expect(selectedEnv.getType()).andReturn(DesignerWorkspaceType.Remote);
EasyMock.expect(selectedEnv.getRemindTime()).andReturn(null);
FunctionalHttpRequest request = EasyMock.mock(FunctionalHttpRequest.class);
EasyMock.expect(request.getServiceList()).andReturn(null);
PowerMock.expectNew(FunctionalHttpRequest.class,connectionInfo).andReturn(request).anyTimes();
EasyMock.expect(request.getServerBranch()).andReturn(remoteBranch);
CheckServiceDialog dialog = EasyMock.mock(CheckServiceDialog.class);
PowerMock.expectNew(CheckServiceDialog.class,EasyMock.anyObject(),EasyMock.anyObject(),EasyMock.anyObject(),EasyMock.anyObject()).andReturn(dialog);
EasyMock.replay(request);
EasyMock.replay(selectedEnv);
EasyMock.replay(connectionInfo);
PowerMock.replayAll();
entrance.showServiceDialog(selectedEnv);
}
}

19
designer-base/src/test/java/com/fr/design/write/submit/CheckServiceDialogTest.java

@ -0,0 +1,19 @@
package com.fr.design.write.submit;
import com.fr.design.mainframe.DesignerContext;
import org.junit.Test;
/**
* @author: Maksim
* @Date: Created in 2020/3/5
* @Description:
*/
public class CheckServiceDialogTest {
@Test
public void dialogTest(){
CheckServiceDialog dialog = new CheckServiceDialog(DesignerContext.getDesignerFrame(), "无","2020-02-01","2020-03-01");
dialog.setVisible(true);
}
}
Loading…
Cancel
Save