Completed
Push — dev ( 39c8fc...3a01d3 )
by Konstantin
11:12 queued 05:12
created

validateAnswer(AnswerModelInterface)   B

Complexity

Conditions 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 19
rs 7.3333
cc 8
1
package easytests.api.v1.validators;
2
3
import easytests.api.v1.exceptions.BadRequestException;
4
import easytests.core.models.AnswerModelInterface;
5
6
/**
7
 * @author SakhPrace
8
 */
9
public class AnswersValidator {
10
11
    public void validateAnswer(AnswerModelInterface answerModel) throws Exception {
0 ignored issues
show
Best Practice introduced by
Dedicated exceptions should be preferred over throwing the generic Exception.
Loading history...
12
13
        if (answerModel.getTxt().length() > 255) {
14
            throw new BadRequestException("Answer text too long");
15
        }
16
        if (!(answerModel.getId() == null)) {
0 ignored issues
show
Comprehensibility introduced by
Inverting the results of boolean operations makes your code less readable. Consider inverting the operation by using != instead.
Loading history...
17
            throw new BadRequestException("Answer Id must be absent");
18
        }
19
        if (!answerModel.getTxt().getClass().getName().equals("String".getClass().getName())) {
0 ignored issues
show
Bug introduced by
Use "isAssignableFrom" instead.

See this CWE advisory on why this is an issue.

Loading history...
20
            throw new BadRequestException("Text in Answer must be String");
21
        }
22
        if (answerModel.getTxt().equals("") || answerModel.getTxt() == null) {
23
            throw new BadRequestException("Text in answer must be not absent");
24
        }
25
        if (!answerModel.getRight().getClass().getName().equals(Boolean.class.getName())) {
0 ignored issues
show
Bug introduced by
Use "isAssignableFrom" instead.

See this CWE advisory on why this is an issue.

Loading history...
26
            throw new BadRequestException("Type of isRight must be boolean");
27
        }
28
        if (!answerModel.getSerialNumber().getClass().getName().equals(Integer.class.getName())) {
0 ignored issues
show
Bug introduced by
Use "isAssignableFrom" instead.

See this CWE advisory on why this is an issue.

Loading history...
29
            throw new BadRequestException("Serial Number must be Integer");
30
        }
31
    }
32
33
}
34