1 package com.atlassian.core.util.thumbnail;
2
3 import junit.framework.TestCase;
4
5 public class AdaptiveThresholdPredicateTest extends TestCase
6 {
7 private static final long KB = 1024L;
8 private static final long MB = KB * 1024;
9 private static final long GB = MB * 1024;
10
11 public void testBasicFunctionality()
12 {
13 AdaptiveThresholdPredicate p = withFreeMemory(KB);
14 assertFalse(p.apply(new Dimensions(100, 100)));
15 assertFalse(p.apply(new Dimensions(10, 100)));
16 assertFalse(p.apply(new Dimensions(10, 25)));
17 assertTrue(p.apply(new Dimensions(10, 10)));
18 assertTrue(p.apply(new Dimensions(4, 10)));
19
20 p = withFreeMemory(Math.round(1.2 * GB));
21 assertFalse(p.apply(new Dimensions(20000, 20000)));
22
23 assertTrue(p.apply(new Dimensions(100, 100)));
24 assertTrue(p.apply(new Dimensions(10, 100)));
25 assertTrue(p.apply(new Dimensions(10, 25)));
26 }
27
28 private AdaptiveThresholdPredicate withFreeMemory(final long freeMemory)
29 {
30 return new AdaptiveThresholdPredicate()
31 {
32 @Override
33 long freeMemory()
34 {
35 return freeMemory;
36 }
37 };
38 }
39 }