@Test @WithMockUser(roles = "Tutor") public void currentMonthBalanceMultipleAppointments() throws Exception { Appointment testAppointment1 = new Appointment(); Appointment testAppointment2 = new Appointment(); LocalDateTime dateTime = LocalDateTime.now(); testAppointment1.setAvailability(Availability.ARRANGED); testAppointment1.setTutor(TestUtility.testUser); testAppointment1.setStudent(TestUtility.testUserTwo); testAppointment1.setWage(BigDecimal.TEN); testAppointment1.setDay(dateTime.getDayOfWeek()); testAppointment1.setTimestamp(Timestamp.valueOf(dateTime)); appointmentDao.save(testAppointment1); testAppointment2.setAvailability(Availability.ARRANGED); testAppointment2.setTutor(TestUtility.testUser); testAppointment2.setStudent(TestUtility.testUserTwo); testAppointment2.setWage(BigDecimal.TEN); testAppointment2.setDay(dateTime.getDayOfWeek()); testAppointment2.setTimestamp(Timestamp.valueOf(dateTime.minusHours(1))); appointmentDao.save(testAppointment2); BigDecimal reference = BigDecimal.TEN.multiply(ConstantVariables.PERCENTAGE); reference = reference.add(BigDecimal.TEN.multiply(ConstantVariables.PERCENTAGE)); mockMvc .perform(get("/bill").principal(this.authUser)) .andExpect(model().attribute("balance", reference.setScale(2))); }
/** * Gets the grid step. * * @param lengthInPixels axis length in pixels * @param min minimum value * @param max maximum value * @return rounded value. */ private BigDecimal getGridStep(int lengthInPixels, double min, double max) { if (lengthInPixels <= 0) { throw new IllegalArgumentException("lengthInPixels must be positive value."); } if (min >= max) { throw new IllegalArgumentException("min must be less than max."); } double length = Math.abs(max - min); double gridStepHint = length / lengthInPixels * axis.getTick().getTickMarkStepHint(); // gridStepHint --> mantissa * 10 ** exponent // e.g. 724.1 --> 7.241 * 10 ** 2 double mantissa = gridStepHint; int exponent = 0; if (mantissa < 1) { while (mantissa < 1) { mantissa *= 10.0; exponent--; } } else { while (mantissa >= 10) { mantissa /= 10.0; exponent++; } } // calculate the grid step with hint. BigDecimal gridStep; if (mantissa > 7.5) { // gridStep = 10.0 * 10 ** exponent gridStep = BigDecimal.TEN.multiply(pow(10, exponent)); } else if (mantissa > 3.5) { // gridStep = 5.0 * 10 ** exponent gridStep = new BigDecimal(new Double(5).toString()).multiply(pow(10, exponent)); } else if (mantissa > 1.5) { // gridStep = 2.0 * 10 ** exponent gridStep = new BigDecimal(new Double(2).toString()).multiply(pow(10, exponent)); } else { // gridStep = 1.0 * 10 ** exponent gridStep = pow(10, exponent); } return gridStep; }