forked from fanruan/finekit
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.6 KiB
125 lines
3.6 KiB
6 years ago
|
package com.fanruan.api.io;
|
||
|
|
||
|
import com.fr.io.base.provider.FactoryLoaderProvider;
|
||
|
import com.fr.io.base.provider.RepositoryFactoryProvider;
|
||
|
import com.fr.io.base.provider.RepositoryInstallerProvider;
|
||
|
import com.fr.io.base.provider.RepositoryManagerProvider;
|
||
|
import com.fr.io.config.RepositoryConfig;
|
||
|
import com.fr.io.config.ResourceModuleConfigProvider;
|
||
|
import com.fr.io.context.RepositoryContextProvider;
|
||
|
import com.fr.io.context.ResourceModuleContext;
|
||
|
import com.fr.io.lock.LockFactory;
|
||
|
import org.easymock.EasyMock;
|
||
|
import org.junit.After;
|
||
|
import org.junit.Assert;
|
||
|
import org.junit.Before;
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* ResourceModuleKit Tester.
|
||
|
*
|
||
|
* @author <Authors name>
|
||
|
* @version 1.0
|
||
|
* @since <pre>9月 5, 2019</pre>
|
||
|
*/
|
||
|
public class ResourceModuleKitTest {
|
||
|
|
||
|
@Before
|
||
|
public void before() throws Exception {
|
||
|
final FactoryLoaderProvider loaderProvider = new FactoryLoaderProvider() {
|
||
|
final Map<String, RepositoryFactoryProvider> map = new HashMap<>();
|
||
|
|
||
|
@Override
|
||
|
public <T extends RepositoryConfig> void add(RepositoryFactoryProvider<T> factory) {
|
||
|
map.put(factory.getIdentity(), factory);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void remove(String identity) {
|
||
|
map.remove(identity);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
@SuppressWarnings("unchecked")
|
||
|
public <T extends RepositoryConfig> RepositoryFactoryProvider<T> get(String identity) {
|
||
|
return map.get(identity);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
ResourceModuleContext.setRepositoryContext(new RepositoryContextProvider() {
|
||
|
@Override
|
||
|
public FactoryLoaderProvider getFactoryLoader() {
|
||
|
|
||
|
return loaderProvider;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ResourceModuleConfigProvider getConfig() {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RepositoryManagerProvider getManager() {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RepositoryInstallerProvider getInstaller() {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public LockFactory getLockFactory() {
|
||
|
return null;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@After
|
||
|
public void after() throws Exception {
|
||
|
ResourceModuleContext.setRepositoryContext(null);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Method: addFactory(@NotNull T factory)
|
||
|
*/
|
||
|
@Test
|
||
|
public void testAddFactory() throws Exception {
|
||
|
RepositoryFactoryProvider factory = EasyMock.createMock(RepositoryFactoryProvider.class);
|
||
|
EasyMock.expect(factory.getIdentity()).andReturn("MockRF").anyTimes();
|
||
|
|
||
|
EasyMock.replay(factory);
|
||
|
|
||
|
Assert.assertNull(ResourceModuleContext.getFactory("MockRF"));
|
||
|
|
||
|
ResourceModuleKit.addFactory(factory);
|
||
|
|
||
|
Assert.assertNotNull(ResourceModuleContext.getFactory("MockRF"));
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Method: addFactory(@NotNull T factory)
|
||
|
*/
|
||
|
@Test
|
||
|
public void testRemoveFactory() throws Exception {
|
||
|
RepositoryFactoryProvider factory = EasyMock.createMock(RepositoryFactoryProvider.class);
|
||
|
EasyMock.expect(factory.getIdentity()).andReturn("MockRF").anyTimes();
|
||
|
|
||
|
EasyMock.replay(factory);
|
||
|
|
||
|
Assert.assertNull(ResourceModuleContext.getFactory("MockRF"));
|
||
|
|
||
|
ResourceModuleKit.addFactory(factory);
|
||
|
|
||
|
Assert.assertNotNull(ResourceModuleContext.getFactory("MockRF"));
|
||
|
|
||
|
ResourceModuleKit.removeFactory(factory);
|
||
|
|
||
|
Assert.assertNull(ResourceModuleContext.getFactory("MockRF"));
|
||
|
}
|
||
|
}
|