refactor tests

This commit is contained in:
Eyck Jentzsch 2021-01-14 23:14:05 +01:00
parent 0372e03abb
commit 6530362b89
3 changed files with 32 additions and 19 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database.test">
<implementation class="com.minres.scviewer.database.test.DatabaseServicesTest"/>
<implementation class="com.minres.scviewer.database.test.TestWaveformDbFactory"/>
<reference bind="setFactory" cardinality="1..1" interface="com.minres.scviewer.database.IWaveformDbFactory" name="IWaveformDbFactory" policy="static" unbind="unsetFactory"/>
</scr:component>

View File

@ -25,28 +25,15 @@ import org.junit.Test;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
public class DatabaseServicesTest {
private static IWaveformDbFactory waveformDbFactory;
private IWaveformDb waveformDb;
public synchronized void setFactory(IWaveformDbFactory service) {
waveformDbFactory = service;
}
public synchronized void unsetFactory(IWaveformDbFactory service) {
if (waveformDbFactory == service) {
waveformDbFactory = null;
}
}
@Before
public void setUp() throws Exception {
waveformDb=waveformDbFactory.getDatabase();
waveformDb=TestWaveformDbFactory.getDatabase();
}
@After
@ -91,11 +78,11 @@ public class DatabaseServicesTest {
assertEquals(1, waveformDb.getChildNodes().size());
for(IWaveform w:waveforms) {
if(w.getId().equals(1l)) {
assertEquals(2, w.getWidth());
assertEquals(2, w.getRowCount());
} else if(w.getId().equals(2l)) {
assertEquals(1, w.getWidth());
assertEquals(1, w.getRowCount());
} else if(w.getId().equals(3l)) {
assertEquals(1, w.getWidth());
assertEquals(1, w.getRowCount());
}
}
}
@ -108,6 +95,7 @@ public class DatabaseServicesTest {
assertNotNull(waveformDb);
assertEquals(3, waveformDb.getAllWaves().size());
assertEquals(1, waveformDb.getChildNodes().size());
while(!waveformDb.isLoaded()) Thread.sleep(10);
}
@Test

View File

@ -0,0 +1,25 @@
package com.minres.scviewer.database.test;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
public class TestWaveformDbFactory {
private static IWaveformDbFactory waveformDbFactory;
public synchronized void setFactory(IWaveformDbFactory service) {
waveformDbFactory = service;
}
public synchronized void unsetFactory(IWaveformDbFactory service) {
if (waveformDbFactory == service) {
waveformDbFactory = null;
}
}
public static IWaveformDb getDatabase() throws Exception {
return waveformDbFactory.getDatabase();
}
}