Browse Source

添加单元测试

research/11.0
kerry 4 years ago
parent
commit
1bc69b0b24
  1. 24
      designer-form/src/test/java/com/fr/design/fit/FitStateCompatibleTest.java
  2. 22
      designer-form/src/test/java/com/fr/design/fit/FormUIModeConfigTest.java
  3. 49
      designer-form/src/test/java/com/fr/design/fit/PXReportLengthUNITTest.java
  4. 64
      designer-form/src/test/java/com/fr/design/fit/PXTest.java
  5. 38
      designer-form/src/test/java/com/fr/design/fit/common/FormDesignerUtilTest.java
  6. 28
      designer-form/src/test/java/com/fr/design/preview/DeveloperPreviewTest.java
  7. 30
      designer-form/src/test/java/com/fr/design/preview/FormAdaptivePreviewTest.java

24
designer-form/src/test/java/com/fr/design/fit/FitStateCompatibleTest.java

@ -0,0 +1,24 @@
package com.fr.design.fit;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by kerry on 2020-04-27
*/
public class FitStateCompatibleTest {
@Test
public void testGetNewTypeFromOld() {
Assert.assertEquals(0, FitStateCompatible.getNewTypeFromOld(0));
Assert.assertEquals(1, FitStateCompatible.getNewTypeFromOld(1));
Assert.assertEquals(0, FitStateCompatible.getNewTypeFromOld(2));
Assert.assertEquals(2, FitStateCompatible.getNewTypeFromOld(3));
}
@Test
public void testGetOldTypeFromNew() {
Assert.assertEquals(2, FitStateCompatible.getOldTypeFromNew(0));
Assert.assertEquals(1, FitStateCompatible.getOldTypeFromNew(1));
Assert.assertEquals(3, FitStateCompatible.getOldTypeFromNew(2));
}
}

22
designer-form/src/test/java/com/fr/design/fit/FormUIModeConfigTest.java

@ -0,0 +1,22 @@
package com.fr.design.fit;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by kerry on 2020-06-05
*/
public class FormUIModeConfigTest {
@Test
public void testSetNewUIMode(){
DesignerUIModeConfig.getInstance().setNewUIMode();
Assert.assertTrue(DesignerUIModeConfig.getInstance().newUIMode());
}
@Test
public void testSetOldUIMode(){
Assert.assertTrue(DesignerUIModeConfig.getInstance().newUIMode());
DesignerUIModeConfig.getInstance().setOldUIMode();
Assert.assertFalse(DesignerUIModeConfig.getInstance().newUIMode());
}
}

49
designer-form/src/test/java/com/fr/design/fit/PXReportLengthUNITTest.java

@ -0,0 +1,49 @@
package com.fr.design.fit;
import com.fr.base.ScreenResolution;
import com.fr.stable.unit.FU;
import org.easymock.EasyMock;
import org.junit.Assert;
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;
/**
* Created by kerry on 2020-04-24
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(ScreenResolution.class)
public class PXReportLengthUNITTest {
@Test
public void testUnitText() {
PXReportLengthUNIT pxReportLengthUNIT = new PXReportLengthUNIT();
Assert.assertEquals(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Px"), pxReportLengthUNIT.unitText());
}
@Test
public void testUnitType() {
PXReportLengthUNIT pxReportLengthUNIT = new PXReportLengthUNIT();
Assert.assertEquals(4, pxReportLengthUNIT.unitType());
}
@Test
public void testUnit2Value4Scale() {
PXReportLengthUNIT pxReportLengthUNIT = new PXReportLengthUNIT();
PowerMock.mockStatic(ScreenResolution.class);
EasyMock.expect(ScreenResolution.getScreenResolution()).andReturn(96).once();
PowerMock.replayAll();
Assert.assertEquals(12, (int) pxReportLengthUNIT.unit2Value4Scale(FU.getInstance(457200L)));
}
@Test
public void testFloat2UNIT() {
PowerMock.mockStatic(ScreenResolution.class);
EasyMock.expect(ScreenResolution.getScreenResolution()).andReturn(96).once();
PowerMock.replayAll();
PXReportLengthUNIT pxReportLengthUNIT = new PXReportLengthUNIT();
Assert.assertEquals(457200L, pxReportLengthUNIT.float2UNIT(12.0F).toFU());
}
}

64
designer-form/src/test/java/com/fr/design/fit/PXTest.java

@ -0,0 +1,64 @@
package com.fr.design.fit;
import com.fr.base.ScreenResolution;
import com.fr.invoke.Reflect;
import org.easymock.EasyMock;
import org.junit.Assert;
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;
import java.math.BigDecimal;
/**
* Created by kerry on 2020-04-26
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(ScreenResolution.class)
public class PXTest {
@Test
public void testGetScaleNumber(){
PowerMock.mockStatic(ScreenResolution.class);
EasyMock.expect(ScreenResolution.getScreenResolution()).andReturn(96).once();
PowerMock.replayAll();
PX px = new PX(100F);
BigDecimal scaleNumber = Reflect.on(px).call("getScaleNumber").get();
Assert.assertEquals(100L, scaleNumber.longValue());
}
@Test
public void testGetMoreFUScale() {
PowerMock.mockStatic(ScreenResolution.class);
EasyMock.expect(ScreenResolution.getScreenResolution()).andReturn(96).times(2);
PowerMock.replayAll();
PX px = new PX(100F);
long fuScale = Reflect.on(px).call("getMoreFUScale").get();
Assert.assertEquals(381L, fuScale);
}
@Test
public void testToPixI(){
PowerMock.mockStatic(ScreenResolution.class);
EasyMock.expect(ScreenResolution.getScreenResolution()).andReturn(96).times(2);
PowerMock.replayAll();
PX px = new PX(100F);
Assert.assertEquals(100, px.toPixI(96));
px = new PX(19.5F);
Assert.assertEquals(19.5F, px.toPixF(96), 0.0F);
}
@Test
public void testToPixWithResolution(){
Assert.assertEquals(100D, PX.toPixWithResolution(100D, 96), 0.0D);
Assert.assertEquals(19.5D, PX.toPixWithResolution(19.5D, 96), 0.0D);
Assert.assertEquals(150D, PX.toPixWithResolution(100D, 144), 0.0D);
Assert.assertEquals(29.25D, PX.toPixWithResolution(19.5D, 144), 0.0D);
}
}

38
designer-form/src/test/java/com/fr/design/fit/common/FormDesignerUtilTest.java

@ -0,0 +1,38 @@
package com.fr.design.fit.common;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kerry on 2020-06-12
*/
public class FormDesignerUtilTest {
@Test
public void testRemoveDeletedEC(){
List<String> list1 = new ArrayList<String>();
List<String> list2 = new ArrayList<String>();
list2.add("test2");
list2.add("test3");
list2.add("test4");
FormDesignerUtil.removeDeletedEC(list1, list2);
Assert.assertEquals(0, list2.size());
list1.add("test1");
list1.add("test3");
list2.add("test2");
list2.add("test3");
list2.add("test4");
FormDesignerUtil.removeDeletedEC(list1, list2);
Assert.assertEquals(1, list2.size());
Assert.assertEquals("test3", list2.get(0));
list1.remove("test3");
FormDesignerUtil.removeDeletedEC(list1, list2);
Assert.assertEquals(0, list2.size());
}
}

28
designer-form/src/test/java/com/fr/design/preview/DeveloperPreviewTest.java

@ -0,0 +1,28 @@
package com.fr.design.preview;
import com.fr.design.mainframe.JForm;
import com.fr.general.web.ParameterConstants;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
/**
* Created by kerry on 2020-04-24
*/
public class DeveloperPreviewTest {
@Test
public void testParametersForPreview() {
DeveloperPreview formPreview = new DeveloperPreview();
Map<String, Object> map = formPreview.parametersForPreview();
Assert.assertEquals(1, map.size());
Assert.assertEquals("developer_preview", map.get(ParameterConstants.OP));
}
@Test
public void testAccept() {
DeveloperPreview formPreview = new DeveloperPreview();
Assert.assertTrue(formPreview.accept(EasyMock.mock(JForm.class)));
}
}

30
designer-form/src/test/java/com/fr/design/preview/FormAdaptivePreviewTest.java

@ -0,0 +1,30 @@
package com.fr.design.preview;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JWorkBook;
import com.fr.general.web.ParameterConstants;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
/**
* Created by kerry on 2020-04-24
*/
public class FormAdaptivePreviewTest {
@Test
public void testParametersForPreview() {
FormAdaptivePreview formPreview = new FormAdaptivePreview();
Map<String, Object> map = formPreview.parametersForPreview();
Assert.assertEquals(1, map.size());
Assert.assertEquals("form_adaptive", map.get(ParameterConstants.OP));
}
@Test
public void testAccept() {
FormAdaptivePreview formPreview = new FormAdaptivePreview();
Assert.assertTrue(formPreview.accept(EasyMock.mock(JForm.class)));
Assert.assertFalse(formPreview.accept(EasyMock.mock(JWorkBook.class)));
}
}
Loading…
Cancel
Save