-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test:proposal service add and view proposal
- Loading branch information
1 parent
a948f37
commit 6fc9d9e
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/nickhumberstone/xpvoting/ProposalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.nickhumberstone.xpvoting; | ||
|
||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class ProposalController { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/com/nickhumberstone/xpvoting/ProposalControllerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.nickhumberstone.xpvoting; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@WebMvcTest(ProposalController.class) | ||
class ProposalControllerIT { | ||
|
||
@Autowired | ||
MockMvc mvc; | ||
|
||
@Test | ||
void should_return_200_for_home_page() throws Exception { | ||
mvc.perform(get("/")) | ||
.andExpect(status().isOk()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/nickhumberstone/xpvoting/ProposalService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
package com.nickhumberstone.xpvoting; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import java.util.Collections; | ||
|
||
public class ProposalService { | ||
List<String> proposals = new ArrayList<>(); | ||
|
||
public List<String> proposals() { | ||
// return proposals; | ||
return Collections.unmodifiableList(proposals); | ||
} | ||
|
||
public void addProposal(String proposal) { | ||
proposals.add(proposal); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/com/nickhumberstone/xpvoting/ProposalServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.nickhumberstone.xpvoting; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ProposalServiceTest { | ||
ProposalService service = new ProposalService(); | ||
|
||
@Test | ||
void should_start_with_no_proposals() { | ||
assertThat(service.proposals()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void should_be_able_to_add_proposal() { | ||
// first add a proposal to the Proposal Service | ||
service.addProposal("Proposal 1"); | ||
// expect our proposal to be in the list | ||
assertThat(service.proposals()).contains("Proposal 1"); | ||
} | ||
|
||
@Test | ||
void should_be_able_to_add_multiple_proposals() { | ||
service.addProposal("Proposal A"); | ||
service.addProposal("Proposal B"); | ||
assertThat(service.proposals()).contains("Proposal A", "Proposal B"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters