@@ -131,6 +131,73 @@ Describe 'JEnv add command' {
131
131
}
132
132
}
133
133
134
+ Describe ' JEnv local command' {
135
+
136
+ BeforeAll {
137
+ $env: Path = $userPath + " ;" + $PSHOME + " ;" + $systemPath
138
+ }
139
+
140
+ It " Should add a valid local" {
141
+ & $jenv local fake1 | Should - Be @ (' fake1' , ' is now your local java version for' , " C:\JEnv-for-Windows\tests" )
142
+ $config = Get-Content - Path ($Env: APPDATA + " \JEnv\jenv.config.json" ) - Raw | ConvertFrom-Json
143
+
144
+ $template = @ ([PSCustomObject ]@ {
145
+ path = " C:\JEnv-for-Windows\tests"
146
+ name = " fake1"
147
+ })
148
+ $config.locals | ConvertTo-Json | Should - Be ($template | ConvertTo-Json )
149
+ }
150
+
151
+ It " Should add a valid local with different path and jdk" {
152
+ Set-Location $HOME
153
+ & $jenv local fake2 | Should - Be @ (' fake2' , ' is now your local java version for' , $HOME )
154
+ $config = Get-Content - Path ($Env: APPDATA + " \JEnv\jenv.config.json" ) - Raw | ConvertFrom-Json
155
+
156
+ $template = @ ([PSCustomObject ]@ {
157
+ path = " C:\JEnv-for-Windows\tests"
158
+ name = " fake1"
159
+ }, [PSCustomObject ]@ {
160
+ path = $HOME
161
+ name = " fake2"
162
+ })
163
+ $config.locals | ConvertTo-Json | Should - Be ($template | ConvertTo-Json )
164
+ }
165
+
166
+ It " Should replace jenv for path if path already in config" {
167
+ & $jenv local fake1 | Should - Be @ (' Your replaced your java version for' , $HOME , ' with' , ' fake1' )
168
+ $config = Get-Content - Path ($Env: APPDATA + " \JEnv\jenv.config.json" ) - Raw | ConvertFrom-Json
169
+
170
+ $template = @ ([PSCustomObject ]@ {
171
+ path = " C:\JEnv-for-Windows\tests"
172
+ name = " fake1"
173
+ }, [PSCustomObject ]@ {
174
+ path = $HOME
175
+ name = " fake1"
176
+ })
177
+ $config.locals | ConvertTo-Json | Should - Be ($template | ConvertTo-Json )
178
+ }
179
+
180
+ It " Should not set a local if jenv was not added to the config" {
181
+ & $jenv local notavaible | Should - Be ' Theres no JEnv with name notavaible Consider using "jenv list"'
182
+ }
183
+
184
+ It " Should remove jenv from config" {
185
+ & $jenv local remove | Should - Be " Your local JEnv was unset"
186
+ $config = Get-Content - Path ($Env: APPDATA + " \JEnv\jenv.config.json" ) - Raw | ConvertFrom-Json
187
+
188
+ $template = @ ([PSCustomObject ]@ {
189
+ path = " C:\JEnv-for-Windows\tests"
190
+ name = " fake1"
191
+ })
192
+ $config.locals | ConvertTo-Json | Should - Be ($template | ConvertTo-Json )
193
+ }
194
+
195
+ AfterAll {
196
+ Set-Location ((get-item $PSScriptRoot ).parent.fullname + " /tests" )
197
+ }
198
+ }
199
+
200
+
134
201
AfterAll {
135
202
Write-Host -----------------------------------------------
136
203
Write-Host Restoring your system from backups
0 commit comments