#Errors Inside LoginController.java

1 messages · Page 1 of 1 (latest)

hidden caveBOT
#

Detected code, here are some useful tools:

[WARNING] The code couldn't end properly...

Problematic source code:

package com.reapp.test;

import static org.junit.Assert.*;

import org.junit.Test;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
 
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
 
import com.reapp.init.BaseTestConfig;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes=BaseTestConfig.class)
public class LoginControllerTest {

  @Autowired
  private WebApplicationContext wac;
 
  private MockMvc mockMvc;
     
  @Before
  public void init() {
    mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
  }

  @Test
  public void testLoginController() throws Exception {
      mockMvc.perform(get("/")).andExpect(status().isOk()).andExpect(view().name()    );
  }
}```
Cause:
The code doesn't compile:
illegal start of expression

## System out
[Nothing]
#

<@&1004656351647117403> please have a look, thanks.

plucky jay
#

What does your pom.xml look like?

#

Or alternatively build.gradle?

hidden caveBOT
#

I uploaded your attachments as Gist.

plucky jay
#

Can you show the output of mvn dependency:tree ?

#

Type in mvn dependency:tree

#

And is your test located inside src/test?

#

Do you have any other tests working?

#

Maybe try to force-reload maven by pressing the reload buttons in your IDE or running mvn clean package to update your dependencies

#

The pom.xml looks kinda fine to me I guess

#

What does your IDE say? Can it find the files and imports?

#

What IDE are you using?

#

Does it have any way to inspect the added dependencies?

#

Can you find spring-test in there?

#

I'd navigate into the spring-test source there and see if the file is in there. Maybe you're using a version that does not contain the files / has a different package structure or something

hidden caveBOT
#

Detected code, here are some useful tools:

plucky jay
#

Yeah no clue, maybe someone else can help.

hidden caveBOT
#

I uploaded your attachments as Gist.

plucky jay
#

Well it shows what dependencies are actually resolved so it would be good to know, yes

#

No clue about STS sadly

#

But generally its just a terminal command you type in

#

To interact with maven

brisk jolt
#

Yes.

dusk ermine
#

Try removing,
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test-mvc</artifactId>
<version>1.0.0.M1</version>
<scope>test</scope>
</dependency>

This version is deprecated. In the shared POM file, I noticed spring-webmvc version 5.2.x, which is sufficient for Spring MVC testing.

hidden caveBOT
#

@vapid quartz

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍