Browse Source

DEC-15442 test: 单元测试

master^2
Dylan.Liu 4 years ago
parent
commit
3d393d6ac0
  1. 24
      src/test/java/com/fanruan/api/cluster/state/FineCollectionsKitTest.java
  2. 2
      src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java
  3. 4
      src/test/java/com/fanruan/api/cluster/state/RedisConfigKitTest.java
  4. 2
      src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java
  5. 17
      src/test/java/com/fanruan/api/cluster/state/StateServerConfigKitTest.java
  6. 39
      src/test/java/com/fanruan/api/cluster/state/StoreTemplateKitTest.java

24
src/test/java/com/fanruan/api/cluster/state/FineCollectionsKitTest.java

@ -0,0 +1,24 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.api.FineCollectionClient;
import com.fr.collections.api.FineCollectionClientWrapper;
import org.junit.Test;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2020/10/23
*/
public class FineCollectionsKitTest {
@Test
public void testGetClient() throws Exception {
// test
FineCollectionClient client = FineCollectionsKit.getClient();
assertTrue(client instanceof FineCollectionClientWrapper);
}
}

2
src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java

@ -19,7 +19,7 @@ import static org.easymock.EasyMock.mock;
public class FineJedisPoolKitTest {
@Test
public void TestSetRealClient() {
public void testSetRealClient() {
FineJedisPoolKit.setRealClient(new FineStoreWrapper() {

4
src/test/java/com/fanruan/api/cluster/state/RedisConfigKitTest.java

@ -13,7 +13,7 @@ import org.junit.Test;
public class RedisConfigKitTest extends Prepare {
@Test
public void TestGetTableNamePrefix() {
public void testGetTableNamePrefix() {
RedisConfig.getInstance().setTableNamePrefix("test_table name_prefix");
Assert.assertEquals("test_table name_prefix", RedisConfigKit.getTableNamePrefix());
@ -23,7 +23,7 @@ public class RedisConfigKitTest extends Prepare {
}
@Test
public void TestGetExpireStateRemoveInterval() {
public void testGetExpireStateRemoveInterval() {
RedisConfig.getInstance().setExpireStateRemoveInterval(111);
Assert.assertEquals(111, RedisConfig.getInstance().getExpireStateRemoveInterval());

2
src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java

@ -18,7 +18,7 @@ import static org.easymock.EasyMock.mock;
public class StandAloneJedisKitTest {
@Test
public void TestCreateStandAloneJedis() {
public void testCreateStandAloneJedis() {
Jedis mockJedis = mock(Jedis.class);
expect(mockJedis.type(anyObject(byte[].class))).andReturn("test_echo");

17
src/test/java/com/fanruan/api/cluster/state/StateServerConfigKitTest.java

@ -13,7 +13,7 @@ import org.junit.Test;
public class StateServerConfigKitTest extends Prepare {
@Test
public void TestGetType() {
public void testGetType() {
StateServerConfig.getInstance().setType("test_type");
Assert.assertEquals("test_type", StateServerConfigKit.getType());
@ -23,7 +23,7 @@ public class StateServerConfigKitTest extends Prepare {
}
@Test
public void TestSetShareMode() {
public void testSetShareMode() {
StateServerConfigKit.setShareMode(true);
Assert.assertTrue(StateServerConfig.getInstance().isShareMode());
@ -33,7 +33,7 @@ public class StateServerConfigKitTest extends Prepare {
}
@Test
public void TestSetType() {
public void testSetType() {
StateServerConfigKit.setType("test_type3");
Assert.assertEquals("test_type3", StateServerConfig.getInstance().getType());
@ -43,8 +43,17 @@ public class StateServerConfigKitTest extends Prepare {
}
@Test
public void TestGetConfigClass() {
public void testGetConfigClass() {
Assert.assertEquals(StateServerConfigKit.getConfigClass(), StateServerConfig.class);
}
@Test
public void testIsShareMode() {
StateServerConfig.getInstance().setShareMode(false);
Assert.assertFalse(StateServerConfigKit.isShareMode());
StateServerConfig.getInstance().setShareMode(true);
Assert.assertTrue(StateServerConfigKit.isShareMode());
}
}

39
src/test/java/com/fanruan/api/cluster/state/StoreTemplateKitTest.java

@ -0,0 +1,39 @@
package com.fanruan.api.cluster.state;
import com.fr.ftp.client.FineSFTPClient;
import com.fr.store.impl.accessor.FineStorePool;
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 static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2020/10/23
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({FineStorePool.class})
public class StoreTemplateKitTest {
@Test
public void testClose() throws Exception {
// test
FineStorePool fineStorePool = mock(FineStorePool.class);
fineStorePool.close();
expectLastCall().times(1);
PowerMock.mockStaticPartial(FineStorePool.class, "getPool");
expect(FineStorePool.getPool()).andReturn(fineStorePool).times(1);
PowerMock.replayAll();
StoreTemplateKit.close();
PowerMock.verifyAll();
}
}
Loading…
Cancel
Save