| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.script.internal.safe; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
import java.util.Collection; |
| 24 |
|
import java.util.LinkedHashMap; |
| 25 |
|
import java.util.LinkedHashSet; |
| 26 |
|
import java.util.List; |
| 27 |
|
import java.util.Map; |
| 28 |
|
import java.util.Set; |
| 29 |
|
|
| 30 |
|
import org.junit.Assert; |
| 31 |
|
import org.junit.Rule; |
| 32 |
|
import org.junit.Test; |
| 33 |
|
import org.xwiki.script.internal.safe.CollectionScriptSafeProvider; |
| 34 |
|
import org.xwiki.script.internal.safe.DefaultScriptSafeProvider; |
| 35 |
|
import org.xwiki.script.internal.safe.MapScriptSafeProvider; |
| 36 |
|
import org.xwiki.script.internal.safe.ScriptSafeProvider; |
| 37 |
|
import org.xwiki.test.annotation.ComponentList; |
| 38 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 39 |
|
|
| 40 |
|
@ComponentList({ CollectionScriptSafeProvider.class, MapScriptSafeProvider.class }) |
| |
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 3 |
Complexity Density: 0.12 |
|
| 41 |
|
public class DefaultScriptSafeProviderTest |
| 42 |
|
{ |
| 43 |
|
@Rule |
| 44 |
|
public MockitoComponentMockingRule<ScriptSafeProvider> mocker = |
| 45 |
|
new MockitoComponentMockingRule<ScriptSafeProvider>(DefaultScriptSafeProvider.class); |
| 46 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 47 |
1 |
@Test... |
| 48 |
|
public void testGetWithNoProvider() throws Exception |
| 49 |
|
{ |
| 50 |
1 |
Object safe = ""; |
| 51 |
|
|
| 52 |
1 |
Assert.assertSame(safe, this.mocker.getComponentUnderTest().get(safe)); |
| 53 |
|
} |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 55 |
1 |
@SuppressWarnings({ "rawtypes", "unchecked" })... |
| 56 |
|
@Test |
| 57 |
|
public void testGetCollection() throws Exception |
| 58 |
|
{ |
| 59 |
|
|
| 60 |
|
|
| 61 |
1 |
Collection unsafe = Arrays.asList("1", "2"); |
| 62 |
1 |
Collection safe = (Collection) this.mocker.getComponentUnderTest().get(unsafe); |
| 63 |
|
|
| 64 |
1 |
Assert.assertNotSame(unsafe, safe); |
| 65 |
1 |
Assert.assertTrue(safe instanceof List); |
| 66 |
1 |
Assert.assertEquals(unsafe, safe); |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
1 |
unsafe = new LinkedHashSet(Arrays.asList("1", "2", "3", "4", "5")); |
| 71 |
1 |
safe = (Collection) this.mocker.getComponentUnderTest().get(unsafe); |
| 72 |
|
|
| 73 |
1 |
Assert.assertNotSame(unsafe, safe); |
| 74 |
1 |
Assert.assertTrue(safe instanceof Set); |
| 75 |
1 |
Assert.assertEquals(unsafe, safe); |
| 76 |
|
|
| 77 |
1 |
Assert.assertEquals(unsafe.toString(), safe.toString()); |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 80 |
1 |
@SuppressWarnings({ "rawtypes", "unchecked", "cast" })... |
| 81 |
|
@Test |
| 82 |
|
public void testGetMap() throws Exception |
| 83 |
|
{ |
| 84 |
1 |
Map unsafe = new LinkedHashMap(5); |
| 85 |
1 |
unsafe.put("1", "1"); |
| 86 |
1 |
unsafe.put("2", "2"); |
| 87 |
1 |
unsafe.put("3", "3"); |
| 88 |
1 |
unsafe.put("4", "4"); |
| 89 |
1 |
unsafe.put("5", "5"); |
| 90 |
1 |
Map safe = (Map) this.mocker.getComponentUnderTest().get(unsafe); |
| 91 |
|
|
| 92 |
1 |
Assert.assertNotSame(unsafe, safe); |
| 93 |
1 |
Assert.assertTrue(safe instanceof Map); |
| 94 |
1 |
Assert.assertEquals(unsafe, safe); |
| 95 |
|
|
| 96 |
1 |
Assert.assertEquals(unsafe.toString(), safe.toString()); |
| 97 |
|
} |
| 98 |
|
} |