-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deny #1
base: master
Are you sure you want to change the base?
Deny #1
Conversation
Always include a .gitignore file in all of your projects. You can base it off of this one: https://github.com/SDiamante13/music-friends-backend/blob/main/.gitignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! You're almost there!
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
Outdated
Show resolved
Hide resolved
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
Show resolved
Hide resolved
@GetMapping("/greetUser") | ||
public String helloUser() { | ||
|
||
return "hello " + userService.helloUser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this feature was to be able to accept a name and greet that person. You should not hard-code Joe into your app. Have it work for any name the consumer passes to you.
User user; | ||
|
||
|
||
public UserService(User user) { this.user = user; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User is a model class that frequently changes so it should not be injected into this class. Instead you would want it to be an input to a method.
return "Hello My Friend !";} | ||
|
||
public String helloUser() { | ||
user.setName("Joe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of setting the name to Joe, pass in the name in the method
|
||
|
||
class UserServiceTest { | ||
private UserService userServiceUnderTest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just userService here is clear enough
private UserService userServiceUnderTest; | |
private UserService userService; |
void shouldReturnStringHellowWorld(){ | ||
//THIS IS FOR J-UNIT 5 JUPITER | ||
//given | ||
String hellow="Hello My Friend !"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a better name for the variable. Tests should be easy to understand
String hellow="Hello My Friend !"; | |
String expectedMessage="Hello My Friend !"; |
//given | ||
String hellow="Hello My Friend !"; | ||
//when | ||
String stringValidity =userServiceUnderTest.helloMessage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String stringValidity =userServiceUnderTest.helloMessage(); | |
String actualMessage =userServiceUnderTest.helloMessage(); |
} | ||
@Test | ||
void shouldReturnStringHellowWorldPlusUserName(){ | ||
user.setName("Joe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try applying my advice about passing in the user into the method and try testing this again.
@RestController | ||
public class UserMainController { | ||
|
||
@Autowired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Autowired |
…s/UserService.java Co-authored-by: Steven Diamante <steven4@vt.edu>
I have tried to read through the comments,and some have been
understood except the idea about the model class , Autowired thing
and constructor dependence injection iam still trying to grasping
…On Sat, May 14, 2022 at 12:31 AM Steven Diamante ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Great job! You're almost there!
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
<#1 (comment)>
:
> @@ -0,0 +1,51 @@
+package com.Deny.MyMentorProject.Services;
+
+import com.Deny.MyMentorProject.User.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
***@***.***
+public class UserService {
+
+ @Autowired
⬇️ Suggested change
- @Autowired
Can remove @Autowired <https://github.com/Autowired> here since you are
using constructor injection below.
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
<#1 (comment)>
:
> +import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
***@***.***
+public class UserService {
+
+ @Autowired
+ User user;
+
+
+ public UserService(User user) { this.user = user;
+ }
+
+
+ public String helloMessage() {
+ return "Hello My Friend !";}
format your code. IntelliJ can do it for you. On Mac, CMD+OPTION+L. On
Windows, CTRL+ALT+L.
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Controllers/UserMainController.java
<#1 (comment)>
:
> +UserService userService;
+
+ public UserMainController(UserService userService) {
+ this.userService = userService;
+ }
+
+ @GetMapping
+ public String helloMessage() {
+
+ return userService. helloMessage();
+ }
+
+ @GetMapping("/greetUser")
+ public String helloUser() {
+
+ return "hello " + userService.helloUser();
The point of this feature was to be able to accept a name and greet that
person. You should not hard-code Joe into your app. Have it work for any
name the consumer passes to you.
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
<#1 (comment)>
:
> @@ -0,0 +1,51 @@
+package com.Deny.MyMentorProject.Services;
+
+import com.Deny.MyMentorProject.User.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
***@***.***
+public class UserService {
+
+ @Autowired
+ User user;
+
+
+ public UserService(User user) { this.user = user;
User is a model class that frequently changes so it should not be injected
into this class. Instead you would want it to be an input to a method.
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
<#1 (comment)>
:
> ***@***.***
+public class UserService {
+
+ @Autowired
+ User user;
+
+
+ public UserService(User user) { this.user = user;
+ }
+
+
+ public String helloMessage() {
+ return "Hello My Friend !";}
+
+ public String helloUser() {
+ user.setName("Joe");
instead of setting the name to Joe, pass in the name in the method
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Services/UserService.java
<#1 (comment)>
:
> + public UserService(User user) { this.user = user;
+ }
+
+
+ public String helloMessage() {
+ return "Hello My Friend !";}
+
+ public String helloUser() {
+ user.setName("Joe");
+ return "hello " + user.getName();
+ }
+ public String messageToReTurn(String messagerequest) {
+
+ String reply = "";
+
+ if (messagerequest ==""){
Feature 3 should be a random greeting. You can create a list of the
statements below and call a randomIndex using java.util.Random.
Hello {User}!
Hey {User}, nice to see you here!
{User} welcome back!
Have a splendid day {User}.
------------------------------
In MyMentorProject/src/main/java/com/Deny/MyMentorProject/User/User.java
<#1 (comment)>
:
> @@ -0,0 +1,49 @@
+package com.Deny.MyMentorProject.User;
+
+
+import org.springframework.stereotype.Service;
+
***@***.***
Remove this as User is constantly changing. Only classes which are
stateless should be initialized as a Spring Bean.
------------------------------
In MyMentorProject/src/main/java/com/Deny/MyMentorProject/User/User.java
<#1 (comment)>
:
> @@ -0,0 +1,49 @@
+package com.Deny.MyMentorProject.User;
+
+
+import org.springframework.stereotype.Service;
+
***@***.***
+public class User {
+
+ private Long id;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ private String name;
Format your code and define your variables first, then the constructors,
then getters and setters, then equals and hash code and toString
------------------------------
In
MyMentorProject/src/test/java/com/Deny/MyMentorProject/Services/UserServiceTest.java
<#1 (comment)>
:
> @@ -0,0 +1,43 @@
+package com.Deny.MyMentorProject.Services;
+
+import com.Deny.MyMentorProject.User.User;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+class UserServiceTest {
+ private UserService userServiceUnderTest;
just userService here is clear enough
⬇️ Suggested change
- private UserService userServiceUnderTest;
+ private UserService userService;
------------------------------
In
MyMentorProject/src/test/java/com/Deny/MyMentorProject/Services/UserServiceTest.java
<#1 (comment)>
:
> +
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+class UserServiceTest {
+ private UserService userServiceUnderTest;
+ private User user;
+ @beforeeach
+ void setUp() {
+ userServiceUnderTest=new UserService(user);
+ }
***@***.***
+ void shouldReturnStringHellowWorld(){
+//THIS IS FOR J-UNIT 5 JUPITER
+ //given
+ String hellow="Hello My Friend !";
Choose a better name for the variable. Tests should be easy to understand
⬇️ Suggested change
- String hellow="Hello My Friend !";
+ String expectedMessage="Hello My Friend !";
------------------------------
In
MyMentorProject/src/test/java/com/Deny/MyMentorProject/Services/UserServiceTest.java
<#1 (comment)>
:
> +
+
+class UserServiceTest {
+ private UserService userServiceUnderTest;
+ private User user;
+ @beforeeach
+ void setUp() {
+ userServiceUnderTest=new UserService(user);
+ }
***@***.***
+ void shouldReturnStringHellowWorld(){
+//THIS IS FOR J-UNIT 5 JUPITER
+ //given
+ String hellow="Hello My Friend !";
+ //when
+ String stringValidity =userServiceUnderTest.helloMessage();
⬇️ Suggested change
- String stringValidity =userServiceUnderTest.helloMessage();
+ String actualMessage =userServiceUnderTest.helloMessage();
------------------------------
In
MyMentorProject/src/test/java/com/Deny/MyMentorProject/Services/UserServiceTest.java
<#1 (comment)>
:
> + userServiceUnderTest=new UserService(user);
+ }
***@***.***
+ void shouldReturnStringHellowWorld(){
+//THIS IS FOR J-UNIT 5 JUPITER
+ //given
+ String hellow="Hello My Friend !";
+ //when
+ String stringValidity =userServiceUnderTest.helloMessage();
+ //then
+ assertEquals(hellow,stringValidity);
+
+ }
+ @test
+ void shouldReturnStringHellowWorldPlusUserName(){
+ user.setName("Joe");
Try applying my advice about passing in the user into the method and try
testing this again.
------------------------------
In
MyMentorProject/src/main/java/com/Deny/MyMentorProject/Controllers/UserMainController.java
<#1 (comment)>
:
> @@ -0,0 +1,39 @@
+package com.Deny.MyMentorProject.Controllers;
+
+import com.Deny.MyMentorProject.Services.UserService;
+import com.Deny.MyMentorProject.User.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
***@***.***
+public class UserMainController {
+
+ @Autowired
⬇️ Suggested change
- @Autowired
—
Reply to this email directly, view it on GitHub
<#1 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWXFZCHBW5XQBA45NPTUYYTVJ3C4LANCNFSM5V3SZNCQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
The two features worked as per the readme and i tried to attempt feature three , and only one test passed