Java Code Examples for org.powermock.reflect.Whitebox#getMethod()
The following examples show how to use
org.powermock.reflect.Whitebox#getMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionKeysTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testTupleRangeCheck() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { // test private static final int[] rangeCheckFields(int[] fields, int maxAllowedField) Method rangeCheckFieldsMethod = Whitebox.getMethod(Keys.class, "rangeCheckFields", int[].class, int.class); // valid indexes rangeCheckFieldsMethod.invoke(null, new int[]{1, 2, 3, 4}, 4); // corner case tests rangeCheckFieldsMethod.invoke(null, new int[] {0}, 0); Throwable ex = null; try { // throws illegal argument. rangeCheckFieldsMethod.invoke(null, new int[] {5}, 0); } catch(Throwable iae) { ex = iae; } Assert.assertNotNull(ex); }
Example 2
Source File: ExpressionKeysTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTupleRangeCheck() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { // test private static final int[] rangeCheckFields(int[] fields, int maxAllowedField) Method rangeCheckFieldsMethod = Whitebox.getMethod(Keys.class, "rangeCheckFields", int[].class, int.class); // valid indexes rangeCheckFieldsMethod.invoke(null, new int[]{1, 2, 3, 4}, 4); // corner case tests rangeCheckFieldsMethod.invoke(null, new int[] {0}, 0); Throwable ex = null; try { // throws illegal argument. rangeCheckFieldsMethod.invoke(null, new int[] {5}, 0); } catch(Throwable iae) { ex = iae; } Assert.assertNotNull(ex); }
Example 3
Source File: ExpressionKeysTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTupleRangeCheck() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { // test private static final int[] rangeCheckFields(int[] fields, int maxAllowedField) Method rangeCheckFieldsMethod = Whitebox.getMethod(Keys.class, "rangeCheckFields", int[].class, int.class); // valid indexes rangeCheckFieldsMethod.invoke(null, new int[]{1, 2, 3, 4}, 4); // corner case tests rangeCheckFieldsMethod.invoke(null, new int[] {0}, 0); Throwable ex = null; try { // throws illegal argument. rangeCheckFieldsMethod.invoke(null, new int[] {5}, 0); } catch(Throwable iae) { ex = iae; } Assert.assertNotNull(ex); }
Example 4
Source File: TelemetryGeneratorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testGetContextWithoutRollUp() throws InvocationTargetException, IllegalAccessException { Method method = Whitebox.getMethod(TelemetryGenerator.class, "getContext", Map.class); Context ctx = (Context) method.invoke(null, context); assertEquals("postman", ctx.getDid()); assertEquals("ORG_001", ctx.getChannel()); assertEquals("User", ctx.getEnv()); }
Example 5
Source File: TelemetryGeneratorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testGetContextWithRollUp() throws InvocationTargetException, IllegalAccessException { rollup.put("id", 1); context.put("rollup", rollup); Method method = Whitebox.getMethod(TelemetryGenerator.class, "getContext", Map.class); Context ctx = (Context) method.invoke(null, context); assertTrue(rollup.equals(ctx.getRollup())); }
Example 6
Source File: TelemetryGeneratorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testRemoveAttributes() throws InvocationTargetException, IllegalAccessException { Method method = Whitebox.getMethod(TelemetryGenerator.class, "removeAttributes", Map.class, String.class); String[] removableProperty = {JsonKey.DEVICE_ID}; method.invoke(null, context, removableProperty); assertFalse(context.containsKey(JsonKey.DEVICE_ID)); }
Example 7
Source File: TelemetryGeneratorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test() public void testGetProducerWithContextNull() throws InvocationTargetException, IllegalAccessException { Map<String, Object> nullContext = null; Method method = Whitebox.getMethod(TelemetryGenerator.class, "getProducer", Map.class); Producer producer = (Producer) method.invoke(null, nullContext); assertEquals("", producer.getId()); assertEquals("", producer.getPid()); assertEquals("", producer.getVer()); }
Example 8
Source File: TelemetryGeneratorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testGetProducerWithAppId() throws InvocationTargetException, IllegalAccessException { context.put("appId", "random"); Method method = Whitebox.getMethod(TelemetryGenerator.class, "getProducer", Map.class); Producer producer = (Producer) method.invoke(null, context); assertEquals("random", producer.getId()); }
Example 9
Source File: TelemetryGeneratorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testGetProducerWithoutAppId() throws InvocationTargetException, IllegalAccessException { context.put("telemetry_pdata_id", "local.sunbird.learning.service"); Method method = Whitebox.getMethod(TelemetryGenerator.class, "getProducer", Map.class); Producer producer = (Producer) method.invoke(null, context); assertEquals("local.sunbird.learning.service", producer.getId()); }
Example 10
Source File: MyCustomMockPolicy.java From powermock-examples-maven with Apache License 2.0 | 5 votes |
/** * Every time the {@link Dependency#getData()} method is invoked we return a * custom instance of a {@link DataObject}. */ @Override public void applyInterceptionPolicy(MockPolicyInterceptionSettings settings) { final Method getDataMethod = Whitebox.getMethod(Dependency.class); final DataObject dataObject = new DataObject("Policy generated data object"); settings.stubMethod(getDataMethod, dataObject); }