'Eclipse debugger JUnit runs pulls wrong class
When I step through my JUnit, I hit a line that runs, and the intended source code is shown in Eclipse. However, the JVM (launched by Eclipse JUnit launcher), does not use the right version. Instead, it's using some other (older) version. Because I'm not sure what's causing this, I'm providing more details than necessary.
I had built this at one point using the Gradle on the command line, and had 2 versions of the same class file. One at /bin/com.woodsman... the other /bin/main/com.woodsman...
I'm using
Java 11
Eclipse: Version: 2021-09 (4.21.0)
Eclipse: Build id: 20210910-1417
Gradle
JUnit 5
Junit Launcher:
Run Single test:
Test Class: com.woodsman.MyClassTest
Test Method: mySingleTest
Test Runner: JUnit 5
Program Argument: None
VM Arguments: -ea
Checked: Use the -XX:+ShowCodeDetails...
Project execution environment 'JavaSE-11'
Dependencies:
Modulepath entries: (empty)
Classpath Entries
JUnit 5 (Advanced Library)
my-project (My Eclipse project)
Project and External Dependencies
JRE System Library [JavaSE-11]
Source:
Default
org.junits (too many to list)
my-project
java ~/my-project/src/test
java ~/my-project/src/main
resource ~/my-project/src/test
resource ~/my-project/src/main
my-project
.git-crypt ~/my-project
.gradle ~/my-project
... many others ...
bin ~/my-project
build ~/my-project
@WebMvcTest(ApiController.class)
class ApiControllerTest extends MVCBaseTest {
@Test
public void generateFeedbackShouldUseBody() throws Exception {
FeedbackResponse feedbackResponse = new FeedbackResponse();
when(toolInvokerService.generateFeedback(any(), any(), any(Boolean.class))).thenReturn(feedbackResponse);
setDinahClient(toolInvokerService);
ObjectNode requestBody = objectMapper.createObjectNode();
requestBody.put("content", "Cellular phones and laptops are used in communication everyone is using it every day.");
final MockHttpServletRequestBuilder request = post("/feedback")
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody.toString());
ResultActions mockResult = mockMvc.perform(request);
String responseBody = mockResult.andReturn().getResponse().getContentAsString();
System.out.println("@@@="+responseBody);
}
}
@Service
public class ToolInvokerService {
private static final Logger log = LoggerFactory.getLogger(ToolInvokerService.class);
private final ContentBuilderService contentBuilderService;
private final ToolNormalizerService toolNormalizerService;
private final FeedbackMapperService feedbackMapperService;
private final LangDetectClient langDetectClient;
private final GrammartoolClient grammarToolClient;
private final AtdClient atdClient;
private final DinahClient dinahClient;
private final CybertronClient cybertronClient;
private final StatsLogger statsLogger;
public ToolInvokerService(
ContentBuilderService contentBuilderService,
ToolNormalizerService toolNormalizerService,
FeedbackMapperService feedbackMapperService,
LangDetectClient langDetectClient,
GrammartoolClient grammarToolClient,
AtdClient atdClient,
DinahClient dinahClient,
CybertronClient cybertronClient,
StatsLogger statsLogger) {
this.contentBuilderService = contentBuilderService;
this.toolNormalizerService = toolNormalizerService;
this.feedbackMapperService = feedbackMapperService;
this.langDetectClient = langDetectClient;
this.grammarToolClient = grammarToolClient;
this.atdClient = atdClient;
this.dinahClient = dinahClient;
this.cybertronClient = cybertronClient;
this.statsLogger = statsLogger;
}
public FeedbackResponse generateFeedback(UserContext userContext, String content, boolean trustLineBreaks) throws
InterruptedException,
ExecutionException,
URISyntaxException,
IOException,
UnsupportedLanguageException {
long startTime = System.currentTimeMillis();
FileOutputStream fop = new FileOutputStream("ben-test.log",true);
fop.write("gfb-bp1\n".getBytes());
if (StringUtils.isEmpty(content)) {
return getEmptyFeedbackResponse(0L);
}
// to reduce call time on long content verify english for up to 5000 characters
langDetectClient.verifyEnglish(CleanTextUtil.truncateText(content, 5000));
fop.write("gfb-bp2\n".getBytes());
fop.write("gfb-bp2.5\n".getBytes());
fop.write(("@@ dinahClient.hashCode()="+dinahClient.hashCode()).getBytes());
fop.write(("@@ dinahClient.toString()="+dinahClient.toString()).getBytes());
ContentMetadataResponse contentMetadata = dinahClient.getContentMetadata(content, trustLineBreaks);
log.info("@@@"+contentMetadata);
if (CollectionUtils.isEmpty(contentMetadata.getContentMetadata().getSentences())) {
log.warn("no sentence content found: returning empty feedback response");
return getEmptyFeedbackResponse(contentMetadata.getTimedResponseDurationMs());
}
List<ToolResponse> toolResponses = getNormalizedToolResponses(userContext.getLocale(), content, contentMetadata.getContentMetadata());
List<Observation> normalizedObservations = new ArrayList<>();
Map<Tool, Long> toolDurations = new HashMap<>();
Map<Tool, Integer> observationCounts = new HashMap<>();
Map<Tool, List<?>> toolErrors = new HashMap<>();
for (ToolResponse toolResponse : toolResponses) {
normalizedObservations.addAll(toolResponse.getNormalizedToolObservations());
toolDurations.put(toolResponse.getTool(), toolResponse.getTimedResponseDurationMs());
observationCounts.put(toolResponse.getTool(), toolResponse.getToolObservations().size());
toolErrors.put(toolResponse.getTool(), toolResponse.getToolErrors());
}
List<Observation> finalObservations = feedbackMapperService.constructFinalObservations(userContext.getLocale(),
normalizedObservations,
content,
contentMetadata.getContentMetadata());
Stats stats = new Stats(
System.currentTimeMillis() - startTime,
contentMetadata.getTimedResponseDurationMs(),
toolDurations,
observationCounts,
contentMetadata.getContentMetadata().getIgnoreSpans());
FeedbackResponse feedbackResponse = new FeedbackResponse(toolErrors, stats, finalObservations);
statsLogger.logResponse(userContext, feedbackResponse, content, normalizedObservations);
return feedbackResponse;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
