コード例 #1
0
  @Before
  public void setup() {
    mockAccountDao = mock(AccountDao.class);
    mockFormDao = mock(FormDao.class);
    mockFormFieldDao = mock(FormFieldDao.class);
    mockAccountService = mock(AccountService.class);

    account = new Account();
    account.setId(1L);
    form = new Form();
    form.setAccount(account);
    form.setFields(new ArrayList<FormField>());
    field = new FormField();
    field.setForm(form);
    form.getFields().add(field);

    when(mockAccountDao.findByUsernameOrEmail("user")).thenReturn(account);
    when(mockFormDao.findById(1L)).thenReturn(form);
    when(mockFormFieldDao.findById(1L)).thenReturn(field);

    formService = new FormService();
    formService.setAccountDao(mockAccountDao);
    formService.setMapper(mapper);
    formService.setFormDao(mockFormDao);
    formService.setFormFieldDao(mockFormFieldDao);
    formService.setAccountService(mockAccountService);
  }
コード例 #2
0
  @Test
  public void deleteFormField() {
    formService.deleteField(1L, 1L, "user");

    ArgumentCaptor<FormField> argument = ArgumentCaptor.forClass(FormField.class);
    verify(mockFormFieldDao).delete(argument.capture());

    assertEquals(field, argument.getValue());
  }
コード例 #3
0
  @Test
  public void modifyForm() {
    ModifyFormDTO dto = new ModifyFormDTO();
    dto.setName("new name");

    formService.modifyForm(1L, dto, "user");

    ArgumentCaptor<Form> argument = ArgumentCaptor.forClass(Form.class);
    verify(mockFormDao).update(argument.capture());

    assertEquals("new name", argument.getValue().getName());
  }
コード例 #4
0
  @Test
  public void createForm() {
    CreateFormDTO createFormDTO = new CreateFormDTO();
    createFormDTO.setName("Dangerous Speech Categorisation");

    formService.createForm(createFormDTO, "user");

    ArgumentCaptor<Form> argument = ArgumentCaptor.forClass(Form.class);
    verify(mockFormDao).create(argument.capture());

    Form form = argument.getValue();
    assertEquals("Dangerous Speech Categorisation", form.getName());

    verify(mockAccountService).logActivity(account, ActivityType.CREATE, form);
  }
コード例 #5
0
  @Test
  public void modifyFormField() {
    ModifyFormFieldDTO dto = new ModifyFormFieldDTO();
    dto.setTitle("New Title");
    dto.setType("multiple");
    dto.setRequired(false);
    dto.setDescription("New Description");
    dto.setOptions(new ArrayList<String>());
    dto.getOptions().add("New Option");

    formService.modifyField(1L, 1L, dto, "user");

    ArgumentCaptor<FormField> argument = ArgumentCaptor.forClass(FormField.class);
    verify(mockFormFieldDao).update(argument.capture());

    FormField field = argument.getValue();
    assertEquals("New Title", field.getTitle());
    assertEquals("multiple", field.getType());
    assertEquals(false, field.getRequired());
    assertEquals("New Description", field.getDescription());
    assertEquals("[\"New Option\"]", field.getOptions());
  }
コード例 #6
0
  @Test
  public void createField() {
    CreateFormFieldDTO dto = new CreateFormFieldDTO();
    dto.setTitle("field title");
    dto.setType("multiple");
    dto.setRequired(true);
    dto.setDescription("field description");
    dto.setOptions(new ArrayList<String>());
    dto.getOptions().add("Test Option");

    formService.createField(1L, dto, "user");

    ArgumentCaptor<FormField> argument = ArgumentCaptor.forClass(FormField.class);
    verify(mockFormFieldDao).create(argument.capture());

    FormField field = argument.getValue();
    assertEquals("field title", field.getTitle());
    assertEquals("multiple", field.getType());
    assertEquals(true, field.getRequired());
    assertEquals("field description", field.getDescription());
    assertEquals("[\"Test Option\"]", field.getOptions());
  }