List of usage examples for java.lang.reflect Method setAccessible
@Override @CallerSensitive public void setAccessible(boolean flag)
From source file:com.smapley.vehicle.utils.LicenseKeyboardUtil.java
private void setSoftKeyboradHide(Activity ctx, EditText edit) { ctx.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); try {/* w w w.ja va2s .c o m*/ Class<EditText> cls = EditText.class; String method_setSoftInputOnFocus = "setShowSoftInputOnFocus"; // method_setSoftInputOnFocus = "setSoftInputOnFocus"; Method setShowSoftInputOnFocus = cls.getMethod(method_setSoftInputOnFocus, boolean.class); setShowSoftInputOnFocus.setAccessible(false); setShowSoftInputOnFocus.invoke(edit, false); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.brienwheeler.svc.authorize_net.impl.AbstractSvcAuthorizeNetTest.java
protected Transaction createTransaction(TransactionType transactionType) throws Exception { CIMClientService target = AopTestUtils.getTarget(cimClientService); Method createTransactionMethod = CIMClientService.class.getDeclaredMethod("createTransaction", TransactionType.class); createTransactionMethod.setAccessible(true); return (Transaction) createTransactionMethod.invoke(target, transactionType); }
From source file:de.haber.xmind2latex.XMindToLatexExporterTest.java
@Test public void testRemoveLineBreaksInComments() { File in = new File("src/test/resources/content.xml"); String[] args = new String[] { "-i", in.getAbsolutePath() }; XMindToLatexExporter exporter;// w w w.j av a 2s . co m try { exporter = CliParameters.build(args); Method getTextForLevel = exporter.getClass().getDeclaredMethod("getTextForLevel", int.class, String.class); assertNotNull(getTextForLevel); getTextForLevel.setAccessible(true); String txt = "a \nb \nc \n"; String undef = (String) getTextForLevel.invoke(exporter, 7, txt); assertTrue(undef.contains(" % 2 - a \n")); assertTrue(undef.contains("\n % - b")); assertTrue(undef.contains("\n % - c")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:com.haulmont.chile.core.model.utils.MethodsCache.java
public MethodsCache(Class clazz) { final Method[] methods = clazz.getMethods(); for (Method method : methods) { String name = method.getName(); if (name.startsWith("get") && method.getParameterTypes().length == 0) { name = StringUtils.uncapitalize(name.substring(3)); method.setAccessible(true); getters.put(name, method);//from ww w . ja v a 2 s . c om } if (name.startsWith("is") && method.getParameterTypes().length == 0) { name = StringUtils.uncapitalize(name.substring(2)); method.setAccessible(true); getters.put(name, method); } else if (name.startsWith("set") && method.getParameterTypes().length == 1) { name = StringUtils.uncapitalize(name.substring(3)); method.setAccessible(true); setters.put(name, method); } } }
From source file:com.spectralogic.ds3client.metadata.WindowsMetadataRestore_Test.java
@Test public void restoreUserAndOwner_Test() throws Exception { final ImmutableMap.Builder<String, String> metadataMap = new ImmutableMap.Builder<>(); final WindowsMetadataStore windowsMetadataStore = new WindowsMetadataStore(metadataMap); final Class aClass = WindowsMetadataStore.class; final Method method = aClass.getDeclaredMethod("saveWindowsDescriptors", new Class[] { Path.class }); method.setAccessible(true); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String fileName = "Gracie.txt"; try {/*from ww w.ja v a 2 s. co m*/ final Path filePath = Files.createFile(Paths.get(tempDirectory.toString(), fileName)); method.invoke(windowsMetadataStore, filePath); final BasicHeader basicHeader[] = new BasicHeader[3]; basicHeader[0] = new BasicHeader(METADATA_PREFIX + KEY_OWNER, metadataMap.build().get(METADATA_PREFIX + KEY_OWNER)); basicHeader[1] = new BasicHeader(METADATA_PREFIX + KEY_GROUP, metadataMap.build().get(METADATA_PREFIX + KEY_GROUP)); basicHeader[2] = new BasicHeader(METADATA_PREFIX + MetadataKeyConstants.KEY_OS, localOS); final Metadata metadata = genMetadata(basicHeader); final WindowsMetadataRestore windowsMetadataRestore = new WindowsMetadataRestore(metadata, filePath.toString(), MetaDataUtil.getOS()); windowsMetadataRestore.restoreOSName(); windowsMetadataRestore.restoreUserAndOwner(); final ImmutableMap.Builder<String, String> mMetadataMapAfterRestore = new ImmutableMap.Builder<>(); final WindowsMetadataStore windowsMetadataStoreAfterRestore = new WindowsMetadataStore( mMetadataMapAfterRestore); final Class aClassAfterRestore = WindowsMetadataStore.class; final Method methodAfterRestore = aClassAfterRestore.getDeclaredMethod("saveWindowsDescriptors", new Class[] { Path.class }); methodAfterRestore.setAccessible(true); methodAfterRestore.invoke(windowsMetadataStoreAfterRestore, filePath); Assert.assertEquals(mMetadataMapAfterRestore.build().get(METADATA_PREFIX + KEY_OWNER), basicHeader[0].getValue()); Assert.assertEquals(mMetadataMapAfterRestore.build().get(METADATA_PREFIX + KEY_GROUP), basicHeader[1].getValue()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }
From source file:de.thkwalter.et.schlupfbezifferung.SchlupfresiduumTest.java
/** * Test der Methode {@link Schlupfresiduum#xKomponentenSchnittpunktBerechnen(double)} fr den Fall, dass der * Steigungswinkel ungleich pi ist.//from w w w .jav a 2s . co m * * @throws SecurityException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalArgumentException * @throws IllegalAccessException */ @Test public void testXKomponentenSchnittpunktBerechnen_ungleichPi() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Die zu testende Methode wird aufgerufen. Method methode = Schlupfresiduum.class.getDeclaredMethod("xKomponentenSchnittpunktBerechnen", double.class); methode.setAccessible(true); double[] xKomponentenSchnittpunkte = (double[]) methode.invoke(this.schlupfresiduum, 1.7426); // Es wird berprft, ob die x-Komponenten der Schnittpunkte der Schlupfgeraden mit den Strahlen vom // Inversionszentrum zu den Betriebspunkten korrekt berechnet worden sind. assertEquals(3, xKomponentenSchnittpunkte.length); assertEquals(5.7183, xKomponentenSchnittpunkte[0], 5.7183 / 1000.0); assertEquals(5.6310, xKomponentenSchnittpunkte[1], 5.6310 / 1000.0); assertEquals(5.4996, xKomponentenSchnittpunkte[2], 5.4996 / 1000.0); }
From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.AliquotIdBreakdownReportServiceFastTest.java
@Test public void testProcessAliquotIdBreakdownPredicatesTrue() throws Exception { Method m = service.getClass().getDeclaredMethod("processAliquotIdBreakdownPredicates", String.class, String.class, String.class); m.setAccessible(true); Predicate p = (Predicate) m.invoke(service, "aliquotId", "mock", "blah"); assertNotNull(p);/*w ww . j a v a 2 s .c om*/ assertTrue(p.evaluate(makeMockAliquotIdBreakdown().get(0))); }
From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.AliquotIdBreakdownReportServiceFastTest.java
@Test public void testProcessAliquotIdBreakdownPredicatesFalse() throws Exception { Method m = service.getClass().getDeclaredMethod("processAliquotIdBreakdownPredicates", String.class, String.class, String.class); m.setAccessible(true); Predicate p = (Predicate) m.invoke(service, "aliquotId", "hum", "blah"); assertNotNull(p);/* w ww.ja v a2s.c om*/ assertFalse(p.evaluate(makeMockAliquotIdBreakdown().get(0))); }
From source file:com.hp.mqm.clt.CliParserTest.java
@Test public void testHelp() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { CliParser parser = new CliParser(); Method help = parser.getClass().getDeclaredMethod("printHelp"); help.setAccessible(true); help.invoke(parser);//from www. j a v a 2 s . c o m }
From source file:com.bitium.confluence.servlet.SsoLoginServlet.java
private void authenticateUserAndLogin(HttpServletRequest request, HttpServletResponse response, String username) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { Authenticator authenticator = SecurityConfigFactory.getInstance().getAuthenticator(); if (authenticator instanceof DefaultAuthenticator) { //DefaultAuthenticator defaultAuthenticator = (DefaultAuthenticator)authenticator; Method getUserMethod = DefaultAuthenticator.class.getDeclaredMethod("getUser", new Class[] { String.class }); getUserMethod.setAccessible(true); Object userObject = getUserMethod.invoke(authenticator, new Object[] { username }); if (userObject != null && userObject instanceof ConfluenceUser) { Principal principal = (Principal) userObject; Method authUserMethod = DefaultAuthenticator.class.getDeclaredMethod( "authoriseUserAndEstablishSession", new Class[] { HttpServletRequest.class, HttpServletResponse.class, Principal.class }); authUserMethod.setAccessible(true); Boolean result = (Boolean) authUserMethod.invoke(authenticator, new Object[] { request, response, principal }); if (result) { String redirectUrl = saml2Config.getRedirectUrl(); if (redirectUrl == null || redirectUrl.equals("")) { redirectUrl = "/confluence/dashboard.action"; }/*w ww. j a v a2 s .co m*/ response.sendRedirect(redirectUrl); return; } } } response.sendRedirect("/confluence/login.action?samlerror=user_not_found"); }