This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileConfTest.java
More file actions
111 lines (92 loc) · 3.28 KB
/
FileConfTest.java
File metadata and controls
111 lines (92 loc) · 3.28 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.jooby;
import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
import java.io.File;
import org.jooby.test.MockUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Jooby.class, File.class, ConfigFactory.class })
public class FileConfTest {
@Test
public void rootFile() throws Exception {
Config conf = ConfigFactory.empty();
new MockUnit()
.expect(unit -> {
unit.mockStatic(ConfigFactory.class);
})
.expect(unit -> {
File dir = unit.constructor(File.class)
.args(String.class)
.build(System.getProperty("user.dir"));
File root = unit.constructor(File.class)
.args(File.class, String.class)
.build(dir, "app.conf");
expect(root.exists()).andReturn(true);
expect(ConfigFactory.parseFile(root)).andReturn(conf);
})
.run(unit -> {
assertEquals(conf, Jooby.fileConfig("app.conf"));
});
}
@Test
public void confFile() throws Exception {
Config conf = ConfigFactory.empty();
new MockUnit()
.expect(unit -> {
unit.mockStatic(ConfigFactory.class);
})
.expect(unit -> {
File dir = unit.constructor(File.class)
.args(String.class)
.build(System.getProperty("user.dir"));
File root = unit.constructor(File.class)
.args(File.class, String.class)
.build(dir, "app.conf");
expect(root.exists()).andReturn(false);
File cdir = unit.constructor(File.class)
.args(File.class, String.class)
.build(dir, "conf");
File cfile = unit.constructor(File.class)
.args(File.class, String.class)
.build(cdir, "app.conf");
expect(cfile.exists()).andReturn(true);
expect(ConfigFactory.parseFile(cfile)).andReturn(conf);
})
.run(unit -> {
assertEquals(conf, Jooby.fileConfig("app.conf"));
});
}
@Test
public void empty() throws Exception {
Config conf = ConfigFactory.empty();
new MockUnit()
.expect(unit -> {
unit.mockStatic(ConfigFactory.class);
})
.expect(unit -> {
File dir = unit.constructor(File.class)
.args(String.class)
.build(System.getProperty("user.dir"));
File root = unit.constructor(File.class)
.args(File.class, String.class)
.build(dir, "app.conf");
expect(root.exists()).andReturn(false);
File cdir = unit.constructor(File.class)
.args(File.class, String.class)
.build(dir, "conf");
File cfile = unit.constructor(File.class)
.args(File.class, String.class)
.build(cdir, "app.conf");
expect(cfile.exists()).andReturn(false);
expect(ConfigFactory.empty()).andReturn(conf);
})
.run(unit -> {
assertEquals(conf, Jooby.fileConfig("app.conf"));
});
}
}