|
| 1 | +package org.gitlab4j.api.models; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 6 | + |
| 7 | +import org.gitlab4j.models.GitLabForm; |
| 8 | +import org.gitlab4j.models.GitLabFormValue; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | + |
| 11 | +public class TestMergeRequestParams { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void testDraftPrefix() { |
| 15 | + MergeRequestParams params = |
| 16 | + new MergeRequestParams().withTitle("My Title").withDraft(true); |
| 17 | + |
| 18 | + GitLabForm form = params.getForm(true); |
| 19 | + Object titleValue = form.getFormValues().get("title").getValue(); |
| 20 | + assertEquals("Draft: My Title", titleValue); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testNoDraftPrefix() { |
| 25 | + MergeRequestParams params = |
| 26 | + new MergeRequestParams().withTitle("My Title").withDraft(false); |
| 27 | + |
| 28 | + GitLabForm form = params.getForm(true); |
| 29 | + Object titleValue = form.getFormValues().get("title").getValue(); |
| 30 | + assertEquals("My Title", titleValue); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testNullDraftPrefix() { |
| 35 | + MergeRequestParams params = |
| 36 | + new MergeRequestParams().withTitle("My Title").withDraft(null); |
| 37 | + |
| 38 | + GitLabForm form = params.getForm(true); |
| 39 | + Object titleValue = form.getFormValues().get("title").getValue(); |
| 40 | + assertEquals("My Title", titleValue); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testDraftWithNullTitle() { |
| 45 | + MergeRequestParams params = new MergeRequestParams().withTitle(null).withDraft(true); |
| 46 | + |
| 47 | + GitLabForm form = params.getForm(true); |
| 48 | + Object titleValue = form.getFormValues().get("title").getValue(); |
| 49 | + assertEquals("Draft: ", titleValue); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testNoDraftWithNullTitle() { |
| 54 | + MergeRequestParams params = new MergeRequestParams().withTitle(null).withDraft(false); |
| 55 | + |
| 56 | + GitLabForm form = params.getForm(true); |
| 57 | + GitLabFormValue titleFormValue = form.getFormValues().get("title"); |
| 58 | + assertNotNull(titleFormValue); |
| 59 | + assertNull(titleFormValue.getValue()); |
| 60 | + } |
| 61 | +} |
0 commit comments