-
Notifications
You must be signed in to change notification settings - Fork 2
/
BeanClassProcessorTest.java
53 lines (42 loc) · 1.6 KB
/
BeanClassProcessorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cz.cvut.kbss.jsonld.common;
import cz.cvut.kbss.jsonld.environment.model.Person;
import cz.cvut.kbss.jsonld.exception.BeanProcessingException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class BeanClassProcessorTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void createNewInstanceCreatesNewClassInstance() {
final Person result = BeanClassProcessor.createInstance(Person.class);
assertNotNull(result);
}
@Test
public void createNewInstanceThrowsBeanProcessingExceptionWhenNoArgConstructorIsMissing() {
thrown.expect(BeanProcessingException.class);
thrown.expectMessage("Class " + ClassWithoutPublicCtor.class + " is missing a public no-arg constructor.");
BeanClassProcessor.createInstance(ClassWithoutPublicCtor.class);
}
private static class ClassWithoutPublicCtor {
private String name;
public ClassWithoutPublicCtor(String name) {
this.name = name;
}
}
@Test
public void testCreateCollectionOfListType() {
final Collection<?> res = BeanClassProcessor.createCollection(CollectionType.LIST);
assertTrue(res instanceof List);
}
@Test
public void testCreateCollectionOfSetType() {
final Collection<?> res = BeanClassProcessor.createCollection(CollectionType.SET);
assertTrue(res instanceof Set);
}
}