2016-08-11 24 views
1

Junitを使用して単体テストクラスを作成しています。また、power-mockingコンセプトを使用して、方法。java.nio.file.FileSystemException:別のプロセスで使用されているため、ファイルにアクセスできません。

テストクラス:

@PowerMockIgnore("javax.management.*") 
@RunWith(PowerMockRunner.class) 
@PrepareForTest(Client.class) 
public class ClientTest { 
private static final Logger logger = LoggerFactory 
     .getLogger(ClientTest.class); 

private static Client client; 

private static DetailsDao detailsDao; 
public static Session session; 
private static IDevicesDao devicesDao; 
private static IUserDao userDao; 
private static IDao dao; 
private static IValidator validator; 



@BeforeClass 
public static void setup() throws Exception { 

    logger.info("*************** Testing ClientTest Started *******************"); 

    session = Connection.get(); // Here getting error 

    detailsDao = mock(DetailsDao.class); 
    devicesDao = mock(IDevicesDao.class); 
    userDao = mock(UserDao.class); 
    validator = mock(IValidator.class); 
    dao= mock(IDao.class); 

    client = new Client(detailsDao, session, devicesDao, userDao, dao, validator); 
} 

私はそのが正常に動作し、その後@RunWith(PowerMockRunner.class)をromove ...しかし、私は唯一のPowerMockRunnerを使用して、このテストを実行する必要がある場合。

例外:パワーモックランナーを使用してカサンドラセッションを作成することができない理由

[10:45:50] sumanth nama: Tests run: 1, Failures: 0, Errors: 1, Skipped: 0,  Time elapsed: 1.234 sec <<< FAILURE! 
com.service.clientTest Time elapsed:  1.234 sec <<< ERROR! 
FSWriteError in target\embeddedCassandra\commitlog\CommitLog-4-1470892233532.log 
at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:135) 
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:381) 
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:377) 
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:377) 
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.rmdir(EmbeddedCassandraSer verHelper.java:266) 
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:81) 
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64) 
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:56) 
at com.charter.aesd.crossmso.wifi.dao.Connection.get(Connection.java:26) 
at com.service.ClientTest.setup(ClientTest.java:76) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:57) 
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) 
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122) 
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106) 
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) 
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59) 
at o rg.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) 
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) 
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) 
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) 
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) 
Caused by: java.nio.file.FileSystemException: target\embeddedCassandra\commitlog\CommitLog-4-1470892233532.log: The process cannot access the file because it is being used by another process. 

私が...得ていないのです....また、セッションを嘲笑

答えて

0

、それはせずに動作します任意のエラー。

session = mock(Session.class); 

session = Connection.get(); 

を置き換え

関連する問題