У меня есть один класс, который будет использоваться для создания списков. Это результат теста:Как назначить номер id заданию To Do?
-----------------------------------------
TESTS - CONSTRUCTOR 1
-----------------------------------------
Construction todo ("description 1")... ➤ [⍡] - 1) description 1() **(expected result in the test)**
id: 1 (System.out.println of the id in the test class)
➤ [⍡] - 1) description 1 **(result)**
OK **(the test is ok)**
Construction todo ("")... OK
Construction todo (null)... OK
------------------------------------------
TESTS - CONSTRUCTOR 2
------------------------------------------
Construction todo (23/08/2016, "description 2")... id : 2 **(here id is 2)**
➤ 23/08/2016 [⍡] - 2) description 2
OK
Construction todo (null, "description 3")... id : 3 **(here id is 3)**
OK
Construction todo (01/01/2016, "xxx")... OK
Construction todo (10/09/2016, "")... OK
Construction todo (10/09/2016, null)... OK
------------------------------------------
TESTS - CONSTRUCTOR 3
------------------------------------------
Construction todo (15/07/2016, "description 4", Todo.HIGH_IMPORTANCE)... **expected** : ➤ 15/07/2016 [⍥] - 4) description 4
**but i got** : ➤ 15/07/2016 [⍥] - 5) description 4 **(on this line the id is 5 instead of 4)**
id: 5 **(System.out.println of the id in test class)**
ERROR **(thats why i have here error)**
Construction todo (null, "description 5", Todo.MEDIUM_IMPORTANCE... id : 6 **(System.out.println in the test class)**
ERROR
Construction todo (01/01/2016, "xxx", Todo.HIGH_IMPORTANCE)... OK
Construction todo (10/09/2016, "", Todo.HIGH_IMPORTANCE)... OK
Construction todo (10/09/2016, null, Todo.HIGH_IMPORTANCE)... OK
------------------------
TESTS - GETTERS
------------------------
GET ID... OK
GET Date creation... OK
GET Dead line... OK
GET Description... OK
GET Description... OK
IS COMPLETED... OK
------------------------
TESTS - SETTERS
------------------------
SET Dead line... OK
SET Completed... OK
SET Level importance... OK
SET Level importance invalid... OK
Checking if the level of importance has not changed... **we expect** : ➤ [⍨] - 5) description 5
**printed result**: ➤ [⍨] - 6) description 5 **(here id is not good, need to be 5)**
ERROR
SET Description... OK
SET Description empty... OK
Checking that the description has not been changed... **we expect** : ➤ 15/07/2016 [⍥] - 4) description 4
**printed result**: ➤ 15/07/2016 [⍥] - 5) description 4
ERROR **(THAT'S WHY ERROR)**
SET Description null... OK
Checking that the description has not been changed... **we expect** : ➤ 15/07/2016 [⍥] - 4) description 4
**printed result**: ➤ 15/07/2016 [⍥] - 5) description 4
ERROR
----------------------------------------------------
TESTS - METHOD OBTENIR GETING LAST ID ASSUMED
----------------------------------------------------
Last id assumed = 5... **id printed is 7**... ERROR
---------------------------------------
TESTS - METHOD HAS PRIORITY OVER
---------------------------------------
Test 1... OK
Test 2... OK
Test 3... OK
Test 4... OK
Test 5... OK
Test 6... OK
Test 7... OK
Test 8... OK
Test 9... OK
Test 10... OK
И это мой класс:
public class Todo {
public static final int HIGH_IMPORTANCE = 1;
public static final int MEDIUM_IMPORTANCE = 2;
public static final int LOW_IMPORTANCE = 3;
private static int lastIdAssumed = 0;
private Date dateCreation;
private Date deadline;
private String description;
private int levelImportance;
private boolean completed;
private int id;
public Todo(String description) throws TodoInvalideException{
if (description != null && description.length() != 0) {
this.description = description;
} else {
throw new TodoInvalideException();
}
this.dateCreation = Date.todayDate();
this.deadline = null;
this.levelImportance = LOW_IMPORTANCE;
this.completed = false;
lastIdAssumed = lastIdAssumed + 1;
this.id = lastIdAssumed;
}
public Todo(Date deadline, String description)throws TodoInvalideException, DateInvalideException {
this(description);
if (deadline != null && dateCreation.estPlusRecente(deadline)){
throw new TodoInvalideException();
}
this.deadline = deadline;
}
public Todo(Date deadline, String description, int levelImportance)throws TodoInvalideException, DateInvalideException{
this(deadline, description);
if (levelImportance == HIGH_IMPORTANCE || levelImportance == MEDIUM_IMPORTANCE
|| levelImportance == LOW_IMPORTANCE) {
this.levelImportance = levelImportance;
} else {
throw new TodoInvalideException();
}
}
//GETTERS (6)
public Date getDateCreation(){
return dateCreation;
}
public Date getDeadline(){
return deadline;
}
public String getDescription(){
return description;
}
public boolean isCompleted(){
return completed;
}
public int getLevelImportance(){
return levelImportance;
}
public int getId(){
return id;
}
//SETTERS (4)
public void setDeadline(Date deadline){
this.deadline = deadline;
}
public void setDescription(String description) throws TodoInvalideException {
if (description != null && description.length() != 0) {
this.description = description;
} else {
throw new TodoInvalideException();
}
}
public void setCompleted(boolean completed){
this.completed = completed;
}
public void setLevelImportance(int levelImportance) throws TodoInvalideException {
if (levelImportance == HIGH_IMPORTANCE || levelImportance == MEDIUM_IMPORTANCE
|| levelImportance == LOW_IMPORTANCE) {
this.levelImportance = levelImportance;
} else {
throw new TodoInvalideException();
}
}
public boolean hasPriorityOver (Todo anotherTodo) throws TodoInvalideException, DateInvalideException {
boolean priorityTodo = false;
if (this.deadline == null && anotherTodo.deadline == null) {
if (this.levelImportance < anotherTodo.levelImportance) {
priorityTodo = true;
}
} else if (this.deadline == null && anotherTodo.deadline != null) {
priorityTodo = false;
} else if (this.deadline != null && anotherTodo.deadline == null) {
priorityTodo = true;
}
if(this.deadline != null && anotherTodo.deadline != null) {
if (anotherTodo.deadline.isMoreRecent(this.deadline)) {
priorityTodo = true;
}else{
priorityTodo = false;
}
if (this.deadline.isEquals(anotherTodo.deadline)) {
if (this.levelImportance < anotherTodo.levelImportance) {
priorityTodo = true;
}else{
priorityTodo = false;
}
}
}
return priorityTodo;
}
public String toString() {
String [] tab = {"", "[\u2365]", "[\u2368]", "[\u2361]"};
String s = "";
if (completed) {
s = s + "\u2714";
} else {
s = s + "\u27A4";
}
if (deadline == null) {
s = s + " ";
} else {
s = s + " " + deadline;
}
s = s + " " + tab[levelImportance];
s = s + " - " + id + ") " + description;
return s;
}
public static int getingLastIdAssumed() {
return lastIdAssumed;
}
}
методы isMoreRecent(), isEquals() и Date.todayDate() находятся в другой класс с именем Date , Большое спасибо!
где вопрос? –
В моем тесте я ошибаюсь ID –
Скорее всего, есть неожиданный класс ToDo, созданный где-то, возможно, в тестовом драйвере. Тот факт, что 'id' назначен из' lastIdAssumed' (который увеличивается), наводит на размышления. Я предполагаю, что проблема заключается в том, что показано на выходе, но, как предложил @RamanShrivastava, было бы проще, если бы вопрос был более прямо сформулирован. – KevinO