Skip to content

Commit 94bb036

Browse files
committed
Polish PortletRequestUtilsTests
Update PortletRequestUtilsTests to use Assert#assertThat and Hamcrest's Matchers#lessThan in order to output more useful messages when tests fail.
1 parent 2ff3d53 commit 94bb036

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

spring-webmvc-portlet/src/test/java/org/springframework/web/portlet/bind/PortletRequestUtilsTests.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,9 @@
2121
import org.springframework.mock.web.portlet.MockPortletRequest;
2222
import org.springframework.util.StopWatch;
2323

24+
import static org.hamcrest.Matchers.*;
25+
import static org.junit.Assert.*;
26+
2427
/**
2528
* @author Juergen Hoeller
2629
* @author Mark Fisher
@@ -370,8 +373,7 @@ public void testGetIntParameterWithDefaultValueHandlingIsFastEnough() {
370373
PortletRequestUtils.getIntParameter(request, "nonExistingParam", 0);
371374
}
372375
sw.stop();
373-
System.out.println(sw.getTotalTimeMillis());
374-
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
376+
assertThat(sw.getTotalTimeMillis(), lessThan(250L));
375377
}
376378

377379
public void testGetLongParameterWithDefaultValueHandlingIsFastEnough() {
@@ -382,8 +384,7 @@ public void testGetLongParameterWithDefaultValueHandlingIsFastEnough() {
382384
PortletRequestUtils.getLongParameter(request, "nonExistingParam", 0);
383385
}
384386
sw.stop();
385-
System.out.println(sw.getTotalTimeMillis());
386-
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
387+
assertThat(sw.getTotalTimeMillis(), lessThan(250L));
387388
}
388389

389390
public void testGetFloatParameterWithDefaultValueHandlingIsFastEnough() {
@@ -394,8 +395,7 @@ public void testGetFloatParameterWithDefaultValueHandlingIsFastEnough() {
394395
PortletRequestUtils.getFloatParameter(request, "nonExistingParam", 0f);
395396
}
396397
sw.stop();
397-
System.out.println(sw.getTotalTimeMillis());
398-
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
398+
assertThat(sw.getTotalTimeMillis(), lessThan(250L));
399399
}
400400

401401
public void testGetDoubleParameterWithDefaultValueHandlingIsFastEnough() {
@@ -406,8 +406,7 @@ public void testGetDoubleParameterWithDefaultValueHandlingIsFastEnough() {
406406
PortletRequestUtils.getDoubleParameter(request, "nonExistingParam", 0d);
407407
}
408408
sw.stop();
409-
System.out.println(sw.getTotalTimeMillis());
410-
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
409+
assertThat(sw.getTotalTimeMillis(), lessThan(250L));
411410
}
412411

413412
public void testGetBooleanParameterWithDefaultValueHandlingIsFastEnough() {
@@ -418,8 +417,7 @@ public void testGetBooleanParameterWithDefaultValueHandlingIsFastEnough() {
418417
PortletRequestUtils.getBooleanParameter(request, "nonExistingParam", false);
419418
}
420419
sw.stop();
421-
System.out.println(sw.getTotalTimeMillis());
422-
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
420+
assertThat(sw.getTotalTimeMillis(), lessThan(250L));
423421
}
424422

425423
public void testGetStringParameterWithDefaultValueHandlingIsFastEnough() {
@@ -430,8 +428,7 @@ public void testGetStringParameterWithDefaultValueHandlingIsFastEnough() {
430428
PortletRequestUtils.getStringParameter(request, "nonExistingParam", "defaultValue");
431429
}
432430
sw.stop();
433-
System.out.println(sw.getTotalTimeMillis());
434-
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
431+
assertThat(sw.getTotalTimeMillis(), lessThan(250L));
435432
}
436433

437434
}

0 commit comments

Comments
 (0)