-
Notifications
You must be signed in to change notification settings - Fork 34
UserActivationServiceImpl.findOlderThan() unit tests #558
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
Conversation
@@ -17,6 +17,7 @@ | |||
*/ | |||
package ru.mystamps.web.service | |||
|
|||
import org.apache.commons.lang3.time.DateUtils |
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.
Откати эту часть с импортом, тут уже был правильный импорт, а это, видимо, IDEA постаралась.
// Tests for findOlderThan() | ||
// | ||
|
||
def "findOlderThan() should throw exception when passed days are less zero"() { |
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.
s/less zero/less than zero/
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.
s/passed days/days/
|
||
def "findOlderThan() should invoke dao, pass changed date and return the result "() { | ||
given: | ||
def days = 4 |
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.
Укажи тип переменной явно.
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.
А параметризованный тест нужно добавить?
Или одного значения хватит?
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.
Я думал об этом, но решил, что и так должно быть достаточно. Поэтому оставлю это на твое усмотрение -- хочешь попробовать -- попробуй, если нет, то оставим как есть.
given: | ||
def days = 4 | ||
and: | ||
def expectedDate = DateUtils.addDays(new Date(), -days) |
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.
Date expectedDate = new Date() + days
thrown IllegalArgumentException | ||
} | ||
|
||
def "findOlderThan() should invoke dao, pass changed date and return the result "() { |
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.
Ты не проверяешь, что метод возвращает значение от дао. Добавишь проверку?
@@ -264,5 +264,30 @@ class UsersActivationServiceImplTest extends Specification { | |||
then: | |||
1 * usersActivationDao.removeByActivationKey(activationKey) | |||
} | |||
|
|||
// | |||
// Tests for findOlderThan() |
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.
Передвинь эти тесты повыше, так чтобы порядок тестируемых методов в тестах совпадал с их порядком объявления этих методов в самом сервисе.
Да, сейчас добавлю. |
Да, разумеется. |
P.S. Там на код CodeNarc ругается, так что надо добавить пару аннотаций (как и в других тестах), чтобы отключить эту ругань. В отчете трэвиса можешь посмотреть подробности. |
Я так понимаю, что CodeNarc ругается на то, что мы делаем замыкание, а он хочет, чтобы в метод передали параметр? |
Ты можешь запустить его локально и проверить: https://github.com/php-coder/mystamps/wiki/codenarc |
Хм, странно. |
Я спать 😴 Если останутся вопросы -- задавай, как будет время, посмотрю. |
Спокойной ночи :) |
Вячеслав, а можно запустить проверку на Travisе без коммита? |
Можно. Все команды, которые выполняются в Travis описаны в его конфигурационном файле: Lines 11 to 35 in 88979cd
Но у тебя падает сейчас только CodeNarc и запустить только его локально довольно просто: https://github.com/php-coder/mystamps/wiki/codenarc |
P.S. Недочитал, видио. На трэвисе без коммита, наверное, могу только я, перезапустив задачу. В твоем случае придется делать коммит. Либо переписывать существующий. А зачем тебе это, к слову? |
Да у меня, просто, CodeNar всегда выдает на консоли Build Success (а в отчете пусто). А также кидает такой exception: А в Travise он пишет, что именно не так. Как вот сейчас, что лучше использовать |
Не удивляюсь, если это баг в самом плагине :( А можешь полное сообщение об ошибке привести (например, сделать скриншот)? |
Похоже на багу либо в плагине либо в самом CodeNarc, который не может корректно обрабатывать пути с пробелами. Попробуй скопировать проект в каталог в пути к которому нет пробелов и запустить проверку там. |
Неа, такую же ошибку выдает :( |
Тогда делай любые коммиты, все равно потом сквошить в один нужно будет :) P.S. |
Хорошо :) |
Нет, из-за бага в danger который я как раз с разработчиками обсуждаю. Можешь засквошить коммиты в один и желательно в авторстве указать имя с фамилией, а не просто имя или нет. Впрочем, если ты не хочешь раскрывать свою фамилию, то это не обязательно. |
Я попробую :) |
35534f9
to
cd354e4
Compare
@@ -264,5 +295,5 @@ class UsersActivationServiceImplTest extends Specification { | |||
then: | |||
1 * usersActivationDao.removeByActivationKey(activationKey) | |||
} | |||
|
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.
Please, remove this useless modification.
@@ -17,6 +17,8 @@ | |||
*/ | |||
package ru.mystamps.web.service | |||
|
|||
import ru.mystamps.web.dao.dto.UsersActivationFullDto | |||
import ru.mystamps.web.tests.DateUtils |
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.
Please, move these imports below, to other import from ru.mystamps
package.
and: | ||
Date expectedDate = new Date() - days | ||
and: | ||
List<UsersActivationFullDto> expectedResult = [] |
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.
Let's compare with non-empty list:
List<UsersActivationFullDto> expectedResult = [ TestObjects.createUsersActivationFullDto() ]
} | ||
|
||
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword']) | ||
def "findOlderThan() should invoke dao, pass changed date and return the result "() { |
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.
and return the result "
Please, remove trailing space at the end of the method name.
What did you decide on that? |
Я указал в commit message имя и фамилию :) |
It's shouldn't be in the message itself but in the author's info: $ git config --global user.name "Your Name"
$ git commit --am --reset-author |
Аа, понял, сделаю тогда сегодня. |
Thanks! And the last thing, please, set the following commit message:
|
Хорошо. |
Yes, I'm expecting a single commit with the provided message. |
cd354e4
to
21f6580
Compare
Generated by 🚫 Danger |
Changes Unknown when pulling 21f6580 on Shagbark:gh337_findOlderThan_utests into ** on php-coder:master**. |
Блин, я же поменял user.name в git config :( |
@Shagbark Еще не поздно :) |
import ru.mystamps.web.validation.ValidationRules | ||
import ru.mystamps.web.dao.dto.UsersActivationFullDto | ||
import ru.mystamps.web.tests.DateUtils |
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.
Старайся уменьшать размер диффа и не меняй ничего, что не относится напрямую к твоему изменению. Так и ревьювить проще, и патч меньше, и ребэйзы проходят с меньшей вероятностью пересечься с другими изменениями и откатывать, в случае чего, тоже проще.
В данном случае, верни, пожалуйста, импорт ru.mystamps.web.tests.DateUtils туда где он был. А импорт ru.mystamps.web.dao.dto.UsersActivationFullDto должен быть после импорта import ru.mystamps.web.dao.dto.UsersActivationDto
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.
Я так понимаю, мне нужно сделать git checkout --UserActivationServiceImpl.java
до определенного коммита, в котором не было изменений, которые не относятся к диффу (либо до начала ветвления)?
А потом добавить 2 теста, с учетом поправок?
Я ни разу не отменял коммит, поэтому спрашиваю :)
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.
It's good that you're asking because I'm expecting that you will edit a file and will execute git commit -a --amend
to add your modifications to the existing commit. Note that existing commit will be overwritten and to push it to the server you will have to use git push -f
.
@@ -264,5 +295,4 @@ class UsersActivationServiceImplTest extends Specification { | |||
then: | |||
1 * usersActivationDao.removeByActivationKey(activationKey) | |||
} | |||
|
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.
См. выше. Коммит не должен содержать ничего лишнего и увеличивать энтропию.
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.
А как можно убрать вот эту строку?
Я сделал git commit -a --amend
, убрал изменения с импортами, а здесь изменения остались?
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.
Для этого ее нужно добавить (вернуть назад) :)
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.
Аа, дурак, понял.
Слушай, а такой вопрос: я сделал git commit -a --amend -am --reset-author
, а все равно запушилось как Shagbark?
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.
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.
Я вижу, что запушилось все ок. Спасибо!
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.
Дай знать как эту строчку победишь :)
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.
Хорошо)
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.
Ура! Я победил :)
21f6580
to
22972d0
Compare
22972d0
to
d59208f
Compare
Отлично! Спасибо! |
Merged in 15e0625 commit. |
Changes Unknown when pulling d59208f on Shagbark:gh337_findOlderThan_utests into ** on php-coder:master**. |
Looks like I forgot to give you this link: https://github.com/php-coder/mystamps/wiki/after_merge_steps |
Addressed to #337