Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
nvim-java/lua/java-test/api.lua at v4.0.3 · nvim-java/nvim-java · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
nvim-java
/
nvim-java
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
95
Star
1.7k
Code
Issues
32
Pull requests
6
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
v4.0.3
Breadcrumbs
nvim-java
/
lua
/
java-test
/
api.lua
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
160 lines (122 loc) · 4.74 KB
v4.0.3
Breadcrumbs
nvim-java
/
lua
/
java-test
/
api.lua
Copy path
Top
File metadata and controls
Code
Blame
160 lines (122 loc) · 4.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
local
log
=
require
(
'
java-core.utils.log2
'
)
local
notify
=
require
(
'
java-core.utils.notify
'
)
local
test_adapters
=
require
(
'
java-test.adapters
'
)
local
dap_adapters
=
require
(
'
java-dap.data-adapters
'
)
local
buf_util
=
require
(
'
java-core.utils.buffer
'
)
local
win_util
=
require
(
'
java.utils.window
'
)
local
DebugClient
=
require
(
'
java-core.ls.clients.java-debug-client
'
)
local
TestClient
=
require
(
'
java-core.ls.clients.java-test-client
'
)
---
@class
java_test.TestApi
---
@field
private
client java-core.JdtlsClient
---
@field
private
debug_client java-core.DebugClient
---
@field
private
test_client java-core.TestClient
---
@field
private
runner java-dap.DapRunner
local
M
=
{}
---
Returns a new test helper client
---
@param
args
{
client
:
vim.lsp.Client
,
runner
:
java-dap.DapRunner
}
---
@return
java_test.TestApi
function
M
:
new
(
args
)
local
o
=
{
client
=
args
.
client
,
}
o
.
debug_client
=
DebugClient
(
args
.
client
)
o
.
test_client
=
TestClient
(
args
.
client
)
o
.
runner
=
args
.
runner
setmetatable
(
o
,
self
)
self
.
__index
=
self
return
o
end
---
Returns a list of test methods
---
@param
file_uri
string uri of the class
---
@return
java-core.TestDetailsWithRange[]
# list of test methods
function
M
:
get_test_methods
(
file_uri
)
log
.
debug
(
'
finding test methods for uri:
'
..
file_uri
)
local
classes
=
self
.
test_client
:
find_test_types_and_methods
(
file_uri
)
local
methods
=
{}
for
_
,
class
in
ipairs
(
classes
)
do
for
_
,
method
in
ipairs
(
class
.
children
)
do
---
@diagnostic
disable-next-line
:
inject-field
method
.
class
=
class
table.insert
(
methods
,
method
)
end
end
log
.
debug
(
'
found
'
..
#
methods
..
'
test methods
'
)
return
methods
end
---
comment
---
@param
buffer
number
---
@param
report
java-test.JUnitTestReport
---
@param
config
?
java-dap.DapLauncherConfigOverridable config to override the default values in test launcher config
function
M
:
run_class_by_buffer
(
buffer
,
report
,
config
)
log
.
debug
(
'
running test class from buffer:
'
..
buffer
)
local
tests
=
self
:
get_test_class_by_buffer
(
buffer
)
if
#
tests
<
1
then
notify
.
warn
(
'
No tests found in the current buffer
'
)
return
end
log
.
debug
(
'
found
'
..
#
tests
..
'
test classes
'
)
self
:
run_test
(
tests
,
report
,
config
)
end
---
Returns test classes in the given buffer
---
@private
---
@param
buffer
integer
---
@return
java-core.TestDetailsWithChildrenAndRange
# get test class details
function
M
:
get_test_class_by_buffer
(
buffer
)
log
.
debug
(
'
finding test class by buffer
'
)
local
uri
=
vim
.
uri_from_bufnr
(
buffer
)
return
self
.
test_client
:
find_test_types_and_methods
(
uri
)
end
---
Run the given test
---
@param
tests
java-core.TestDetails[]
---
@param
report
java-test.JUnitTestReport
---
@param
config
?
java-dap.DapLauncherConfigOverridable config to override the default values in test launcher config
function
M
:
run_test
(
tests
,
report
,
config
)
log
.
debug
(
'
running
'
..
#
tests
..
'
tests
'
)
local
launch_args
=
self
.
test_client
:
resolve_junit_launch_arguments
(
test_adapters
.
tests_to_junit_launch_params
(
tests
))
log
.
debug
(
'
resolved launch args - mainClass:
'
..
launch_args
.
mainClass
..
'
, projectName:
'
..
launch_args
.
projectName
)
local
java_exec
=
self
.
debug_client
:
resolve_java_executable
(
launch_args
.
mainClass
,
launch_args
.
projectName
)
log
.
debug
(
'
java executable
'
,
java_exec
)
local
dap_launcher_config
=
dap_adapters
.
junit_launch_args_to_dap_config
(
launch_args
,
java_exec
, {
debug
=
true
,
label
=
'
Launch All Java Tests
'
,
})
dap_launcher_config
=
vim
.
tbl_deep_extend
(
'
force
'
,
dap_launcher_config
,
config
or
{})
log
.
debug
(
'
launching tests with config
'
,
dap_launcher_config
)
self
.
runner
:
run_by_config
(
dap_launcher_config
,
report
)
end
---
Run the current test class
---
@param
report
java-test.JUnitTestReport
---
@param
config
java-dap.DapLauncherConfigOverridable
function
M
:
execute_current_test_class
(
report
,
config
)
log
.
debug
(
'
running the current class
'
)
return
self
:
run_class_by_buffer
(
buf_util
.
get_curr_buf
(),
report
,
config
)
end
---
Run the current test method
---
@param
report
java-test.JUnitTestReport
---
@param
config
java-dap.DapLauncherConfigOverridable
function
M
:
execute_current_test_method
(
report
,
config
)
log
.
debug
(
'
running the current method
'
)
local
method
=
self
:
find_current_test_method
()
if
not
method
then
notify
.
warn
(
'
cursor is not on a test method
'
)
return
end
self
:
run_test
({
method
},
report
,
config
)
end
---
Find the test method at the current cursor position
---
@return
java-core.TestDetailsWithRange
|
nil
function
M
:
find_current_test_method
()
log
.
debug
(
'
finding the current test method
'
)
local
cursor
=
win_util
.
get_cursor
()
local
methods
=
self
:
get_test_methods
(
buf_util
.
get_curr_uri
())
for
_
,
method
in
ipairs
(
methods
)
do
local
line_start
=
method
.
range
.
start
.
line
local
line_end
=
method
.
range
[
'
end
'
].
line
if
cursor
.
line
>=
line_start
and
cursor
.
line
<=
line_end
then
return
method
end
end
end
return
M
You can’t perform that action at this time.