/** Create a user, create a state and make him answer a few questions. */ @Before public void setup() { // setup user expectedUser = new User("xuser"); expectedUser.setId(1234); // setup level expectedLevel = QuestionLevel.LEVEL_1; // setup question expectedQuestion = new Question(); expectedQuestion.setAnswer("xanswer"); expectedQuestion.setType(QuestionType.TEXT); expectedQuestion.setCategory(QuestionCategory.SHAPES); List<String> choices = new ArrayList(); choices.add("apple"); choices.add("orange"); choices.add("banana"); choices.add("cherry"); expectedQuestion.setChoices(choices); expectedQuestion.setLevel(expectedLevel); expectedQuestion.setQuestion("xquestion"); expectedQuestion.setExplaination("xplanation"); // set current question and level for user expectedUser.setCurrentQuestion(expectedQuestion); expectedUser.endState(); fileUserManager.addUser(expectedUser); }
/** Check if the state was saved successfully to the user profile. */ @Test public void statesAreSaved() { User actual = fileUserManager.getUser("xuser"); Question actualQuestion = actual.getState().getCurrentQuestion(); QuestionLevel actualLevel = actual.getState().getCurrentLevel(); assertEquals(actualQuestion, expectedQuestion); }
/** Add a score the the user and check if the score is saved. */ @Test public void addScore() { Integer expectedScore = 4; expectedUser.saveScore(expectedQuestion, expectedScore); Map<Question, Integer> map = new HashMap(); map = expectedUser.getState().getAllScores(); Integer actualScore = map.get(expectedQuestion); assertEquals(expectedScore, actualScore); expectedUser.newState(QuestionCategory.COLORS, QuestionLevel.LEVEL_2); map = new HashMap(); map = expectedUser.getState().getAllScores(); assertEquals(map.size(), 0); Object[][] objects = new Object[1][2]; objects = expectedUser.getHistory(QuestionCategory.SHAPES, QuestionLevel.LEVEL_1); assertEquals("xquestion", objects[0][0]); }
/** Check if the user was added successfully to database. */ @Test public void usersAreAdded() { User actual = fileUserManager.getUser("xuser"); assertEquals(actual.getName(), expectedUser.getName()); assertEquals(actual.getId(), expectedUser.getId()); }