我正在调用一个名为"calculateStampDuty"的方法,该方法将返回要在房产上支付的印花税金额.百分比计算工作正常,并返回正确的值"15000.0".但是,我想将前端用户的值显示为"15000",因此只想删除小数和之后的任何值.如何才能做到这一点?我的代码如下:
float HouseValue = 150000;
double percentageValue;
percentageValue = calculateStampDuty(10, HouseValue);
private double calculateStampDuty(int PercentageIn, double HouseValueIn){
double test = PercentageIn * HouseValueIn / 100;
return test;
}
Run Code Online (Sandbox Code Playgroud)
我尝试过以下方法:
创建一个新的字符串,将double值转换为字符串,如下所示:
String newValue = percentageValue.toString();
我尝试在String对象上使用'valueOf'方法,如下所示:
String total2 = String.valueOf(percentageValue);
但是,我只是无法获得没有小数位的值.在这个例子中有没有人知道如何获得"15000"而不是"15000.0"?
谢谢
我试图使用Mockito测试一些遗留代码,并且该方法是void类型.
我已经在其他类中省略了很多对方法的调用,这很好用.但是,我还需要能够在同一个类中删除对其他方法的某些调用.
目前这不起作用.
例如,我的班级如下:
public class Test {
public Test(dummy dummy) {
}
public void checkTask(Task task, List <String> dependencyOnLastSuccessList) throws TaskException {
callToOtherClass.method1 // This works fine, I can stub it using mockito
updateAndReschedule(Long id, String message) // call to method in same class, I cannot stub it
}
public void updateAndReschedule(Long id, String message) {
//method logic.....
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的testClass显示我现在的情况:
@Test
public void testMyMethod() {
Test testRef = new Test(taskJob);
Test spy = spy (testRef);
// when a …Run Code Online (Sandbox Code Playgroud) 我正在通过 Spring MVC 创建一个基本的登录页面。到目前为止,我已经创建了以下内容:
我的单元测试失败,出现以下异常:
org.springframework.beans.NotReadablePropertyException: Invalid property 'login' of bean class [springapp.service.LoginValidator]: Bean property 'login' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:707)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:699)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:105)
at springapp.service.LoginValidator.validateUsername(LoginValidator.java:44)
at springapp.service.LoginValidator.validate(LoginValidator.java:27)
at springapp.service.LoginValidatorTests.testEmptyUsernameAndPassword(LoginValidatorTests.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124) …Run Code Online (Sandbox Code Playgroud)