### Question:
RangerPolicyResourceSignature { @Override public String toString() { return String.format("%s: %s", _hash, _string); } RangerPolicyResourceSignature(RangerPolicy policy);   RangerPolicyResourceSignature(String string); String getSignature(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString();  }### Answer:
@Test public void test_RangerPolicyResourceView_toString() { RangerPolicyResource resource = null; ResourceSerializer serializer = new ResourceSerializer(resource); assertEquals("{}", serializer.toString()); resource = createPolicyResource(null, null, null); serializer = new ResourceSerializer(resource); assertEquals("{values=,excludes=false,recursive=false}", serializer.toString()); resource = createPolicyResource(new String[]{"b", "a", "d", "c"}, true, false); serializer = new ResourceSerializer(resource); assertEquals("{values=[a, b, c, d],excludes=false,recursive=true}", serializer.toString()); resource = createPolicyResource(new String[]{"9", "A", "e", "_"}, false, true); serializer = new ResourceSerializer(resource); assertEquals("{values=[9, A, _, e],excludes=true,recursive=false}", serializer.toString()); }
@Test public void test_getResourceSignature_happyPath() { RangerPolicy policy = null; PolicySerializer serializer = new PolicySerializer(policy); assertTrue("Null policy", serializer.toString() == ""); policy = mock(RangerPolicy.class); when(policy.getPolicyType()).thenReturn(null); Map<String, RangerPolicyResource> policyResources = _utils.createPolicyResourceMap(first); when(policy.getResources()).thenReturn(policyResources); serializer = new PolicySerializer(policy); String expectedVersion = "version=1"; String expectedType = "type=0"; String expectedResource = "{" + "col={values=[col1, col2, col3],excludes=false,recursive=true}, " + "db={values=[db1, db2],excludes=false,recursive=false}, " + "table={values=[tbl1, tbl2, tbl3],excludes=true,recursive=false}" + "}"; String serializationFormat = "{%s,%s,resource=%s}"; String expectedFull = String.format(serializationFormat, expectedVersion, expectedType, expectedResource); assertEquals(expectedFull, serializer.toString()); policyResources = _utils.createPolicyResourceMap(data_second); when(policy.getResources()).thenReturn(policyResources); assertEquals(expectedFull, serializer.toString()); when(policy.getPolicyType()).thenReturn(1); expectedType="type=1"; expectedFull = String.format(serializationFormat, expectedVersion, expectedType, expectedResource); assertEquals(expectedFull, serializer.toString()); }
@Test public void test_nullRecursiveFlagIsSameAsFlase() { RangerPolicy policy1 = createPolicy(first); RangerPolicy policy2 = createPolicy(first_recursive_null_or_false); RangerPolicyResourceSignature signature1 = new RangerPolicyResourceSignature(policy1); RangerPolicyResourceSignature signature2 = new RangerPolicyResourceSignature(policy2); assertEquals("Recursive flag: null is same as false", signature1.toString(), signature2.toString()); }
@Test public void test_nullExcludesFlagIsSameAsFlase() { RangerPolicy policy1 = createPolicy(first); RangerPolicy policy2 = createPolicy(first_excludes_null_or_false); RangerPolicyResourceSignature signature1 = new RangerPolicyResourceSignature(policy1); RangerPolicyResourceSignature signature2 = new RangerPolicyResourceSignature(policy2); assertEquals("Excludes flag: null is same as false", signature1.toString(), signature2.toString()); }