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 package com.qulice.spi;
32
33 import java.io.File;
34 import org.hamcrest.MatcherAssert;
35 import org.hamcrest.Matchers;
36 import org.junit.jupiter.api.Test;
37
38
39
40
41
42 final class EnvironmentTest {
43
44
45
46
47
48 @Test
49 void canBeInstantiatedWithMocker() throws Exception {
50 final Environment env = new Environment.Mock();
51 MatcherAssert.assertThat(
52 "Basedir should exist", env.basedir().exists(), Matchers.is(true)
53 );
54 MatcherAssert.assertThat(
55 "Tempdir should exist", env.tempdir().exists(), Matchers.is(true)
56 );
57 MatcherAssert.assertThat(
58 "Outdir should exist", env.outdir().exists(), Matchers.is(true)
59 );
60 }
61
62
63
64
65
66 @Test
67 void writesFileContentToTheDesignatedLocation() throws Exception {
68 final String name = "src/main/java/Main.java";
69 final String content = "class Main {}";
70 final Environment env = new Environment.Mock()
71 .withFile(name, content);
72 final File file = new File(env.basedir(), name);
73 MatcherAssert.assertThat(
74 "File should be created in basedir from string value",
75 file.exists(), Matchers.is(true)
76 );
77 }
78
79
80
81
82
83 @Test
84 void writesByteArrayToTheDesignatedLocation() throws Exception {
85 final String name = "src/main/java/Foo.java";
86 final byte[] bytes = "class Foo {}".getBytes();
87 final Environment env = new Environment.Mock()
88 .withFile(name, bytes);
89 final File file = new File(env.basedir(), name);
90 MatcherAssert.assertThat(
91 "File should be created in basedir from bytes",
92 file.exists(), Matchers.is(true)
93 );
94 }
95
96
97
98
99
100 @Test
101 void setsClasspathOnTheMock() throws Exception {
102 final Environment env = new Environment.Mock();
103 MatcherAssert.assertThat(
104 "Classpath should be not empty",
105 env.classpath().size(),
106 Matchers.greaterThan(0)
107 );
108 }
109
110
111
112
113
114 @Test
115 void configuresParametersInMock() throws Exception {
116 final String name = "alpha";
117 final String value = "some complex value";
118 final Environment env = new Environment.Mock()
119 .withParam(name, value);
120 MatcherAssert.assertThat(
121 "Environment variable should be set",
122 env.param(name, ""), Matchers.equalTo(value)
123 );
124 }
125
126 }