Skip to content

Commit c15e1ea

Browse files
committed
add tests
1 parent b420cea commit c15e1ea

File tree

8 files changed

+91
-8
lines changed

8 files changed

+91
-8
lines changed

net.lecousin.core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<exclude>**/ThreadingDebugHelper*.*</exclude>
147147
<exclude>**/TaskMonitoring*.*</exclude>
148148
<exclude>**/DebugUtil*.*</exclude>
149+
<exclude>**/SystemEnvironment.*</exclude>
149150
</excludes>
150151
</configuration>
151152
</plugin>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
public class NoPackageClass {
3+
4+
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/test/io/TestIO.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import net.lecousin.framework.concurrent.Task;
1414
import net.lecousin.framework.concurrent.synch.ISynchronizationPoint;
1515
import net.lecousin.framework.core.test.LCCoreAbstractTest;
16+
import net.lecousin.framework.event.Listener;
1617
import net.lecousin.framework.io.FileIO;
1718
import net.lecousin.framework.io.IO;
1819
import net.lecousin.framework.mutable.MutableBoolean;
20+
import net.lecousin.framework.util.CloseableListenable;
1921

2022
public abstract class TestIO extends LCCoreAbstractTest {
2123

@@ -116,17 +118,29 @@ public void testBasicCommonFunctions() throws Exception {
116118
basicTests(io);
117119
// closeable
118120
MutableBoolean closed = new MutableBoolean(false);
121+
MutableBoolean closed2 = new MutableBoolean(false);
122+
Runnable listener1 = () -> {};
123+
Listener<CloseableListenable> listener2 = (toto) -> {};
119124
io.addCloseListener(() -> {
120125
closed.set(true);
121126
});
127+
io.addCloseListener((toto) -> {
128+
closed2.set(true);
129+
});
130+
io.addCloseListener(listener1);
131+
io.addCloseListener(listener2);
122132
io.lockClose();
123133
ISynchronizationPoint<Exception> close = io.closeAsync();
124134
Assert.assertFalse(io.isClosed());
125135
Assert.assertFalse(close.isUnblocked());
126136
Assert.assertFalse(closed.get());
137+
Assert.assertFalse(closed2.get());
138+
io.removeCloseListener(listener1);
139+
io.removeCloseListener(listener2);
127140
io.unlockClose();
128141
close.blockThrow(0);
129142
Assert.assertTrue(closed.get());
143+
Assert.assertTrue(closed2.get());
130144
Assert.assertTrue(io.isClosed());
131145
}
132146

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.lecousin.framework.core.tests.concurrent;
2+
3+
import org.junit.Test;
4+
5+
import net.lecousin.framework.application.LCCore;
6+
import net.lecousin.framework.concurrent.Console;
7+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
8+
9+
public class TestConsole extends LCCoreAbstractTest {
10+
11+
@Test(timeout=30000)
12+
public void test() {
13+
Console c = LCCore.getApplication().getConsole();
14+
c.out(new Exception("test"));
15+
c.err(new Exception("test"));
16+
}
17+
18+
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/concurrent/TestDrivesTaskManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public void provide(
5050
Listener<Pair<Object, File>> onPartitionRemoved
5151
) {
5252
onNewDrive.fire(new Pair<>(fakeDrive1, Collections.singletonList(tmpDir)));
53+
onNewPartition.fire(new Pair<>(fakeDrive1, dir));
54+
onPartitionRemoved.fire(new Pair<>(fakeDrive1, dir));
5355
spDrive2Appear.listenInline(() -> {
5456
onNewDrive.fire(new Pair<>(fakeDrive2, Collections.singletonList(tmpDir)));
5557
spDrive2AppearDone.unblock();

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/memory/TestCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public void test() throws Exception {
3636
Assert.assertEquals(1, cache.getCachedData().iterator().next().cachedDataCurrentUsage());
3737
// use it with a user
3838
CloseableListenable user = new CloseableListenable.Impl();
39+
user.isClosed();
40+
Runnable listener = () -> {};
41+
user.addCloseListener(listener);
42+
user.removeCloseListener(listener);
3943
Assert.assertEquals(1, cache.get("test", user).intValue());
4044
Assert.assertEquals(1, cache.getCachedData().size());
4145
Assert.assertEquals(2, cache.getCachedData().iterator().next().cachedDataCurrentUsage());

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/util/TestClassUtil.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package net.lecousin.framework.core.tests.util;
22

3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
36
import net.lecousin.framework.core.test.LCCoreAbstractTest;
47
import net.lecousin.framework.properties.Property;
58
import net.lecousin.framework.util.ClassUtil;
69

7-
import org.junit.Assert;
8-
import org.junit.Test;
9-
1010
public class TestClassUtil extends LCCoreAbstractTest {
1111

1212
public static class Class1 {
@@ -37,6 +37,13 @@ public static void setMyBoolean3(@SuppressWarnings("unused") boolean value) {
3737
public boolean getMyBoolean() {
3838
return myBoolean;
3939
}
40+
41+
protected boolean getMyBoolean2(int notused) {
42+
return false;
43+
}
44+
protected boolean isMyBoolean2(int notused) {
45+
return false;
46+
}
4047

4148
protected boolean getMyBoolean2() {
4249
return false;
@@ -52,6 +59,19 @@ public boolean isOk() {
5259
}
5360
}
5461

62+
public static class Class4 {
63+
boolean bool;
64+
Boolean bool2;
65+
boolean bool3;
66+
Boolean bool4;
67+
int i;
68+
public boolean getBool(int toto) { return true; }
69+
public boolean isBool(int toto) { return true; }
70+
public static boolean isBool2() { return true; }
71+
public int isBool3() { return 0; }
72+
public Boolean isBool4() { return bool4; }
73+
}
74+
5575
@Test(timeout=30000)
5676
public void testGetAllFieldsInheritedFirst() {
5777
//ArrayList<Field> fields =
@@ -74,6 +94,12 @@ public void testGettersAndSetters() {
7494
Assert.assertNotNull(ClassUtil.getSetter(Class2.class, "myBoolean").getAnnotation(Property.class));
7595
Assert.assertNull(ClassUtil.getSetter(Class2.class, "myBoolean2"));
7696
Assert.assertNull(ClassUtil.getSetter(Class2.class, "myBoolean3"));
97+
98+
Assert.assertNull(ClassUtil.getGetter(Class4.class, "bool"));
99+
Assert.assertNull(ClassUtil.getGetter(Class4.class, "bool2"));
100+
Assert.assertNull(ClassUtil.getGetter(Class4.class, "bool3"));
101+
Assert.assertNotNull(ClassUtil.getGetter(Class4.class, "bool4"));
102+
Assert.assertNull(ClassUtil.getGetter(Class4.class, "i"));
77103
}
78104

79105
@SuppressWarnings("unused")
@@ -128,4 +154,9 @@ public void testGetMethods() {
128154
Assert.assertEquals(1, ClassUtil.getMethods(Class2.class, "setMyBoolean", 1).size());
129155
}
130156

157+
@Test(timeout=30000)
158+
public void test() throws ClassNotFoundException {
159+
Assert.assertEquals("", ClassUtil.getPackageName(getClass().getClassLoader().loadClass("NoPackageClass")));
160+
}
161+
131162
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/util/TestUnprotectedString.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package net.lecousin.framework.core.tests.util;
22

3+
import java.nio.ByteBuffer;
4+
import java.nio.charset.StandardCharsets;
35
import java.util.Arrays;
46
import java.util.Collection;
57

6-
import net.lecousin.framework.core.test.util.TestIString;
7-
import net.lecousin.framework.util.IString;
8-
import net.lecousin.framework.util.UnprotectedString;
9-
import net.lecousin.framework.util.UnprotectedStringBuffer;
10-
118
import org.junit.Assert;
129
import org.junit.Test;
1310
import org.junit.runner.RunWith;
1411
import org.junit.runners.Parameterized;
1512
import org.junit.runners.Parameterized.Parameters;
1613

14+
import net.lecousin.framework.core.test.util.TestIString;
15+
import net.lecousin.framework.util.IString;
16+
import net.lecousin.framework.util.UnprotectedString;
17+
import net.lecousin.framework.util.UnprotectedStringBuffer;
18+
1719
@RunWith(Parameterized.class)
1820
public class TestUnprotectedString extends TestIString {
1921

@@ -88,4 +90,11 @@ public void testAppend() {
8890
Assert.assertEquals("Hello World!", s.asString());
8991
}
9092

93+
@Test(timeout=30000)
94+
public void test() {
95+
UnprotectedString s = new UnprotectedString("Hello");
96+
ByteBuffer bb = s.encode(StandardCharsets.UTF_8);
97+
// TODO check
98+
}
99+
91100
}

0 commit comments

Comments
 (0)