@Test public void testNoModuleFactory() throws Exception { final Checker checker = new Checker(); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); checker.finishLocalSetup(); }
public void putAll(Map<? extends K, ? extends V> map) { for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { Checker.checkType(entry.getKey()); Checker.checkType(entry.getValue()); this.map.put(entry.getKey(), entry.getValue()); } }
private GameObj shiftChecker(GameObj obj, int x, int y) { Color c = obj.getColor(); Checker ret = new Checker(x, y, c); if (obj.isQueen()) { ret.makeQueen(); } return ret; }
@SuppressWarnings("deprecation") @Test public void testSetters() throws Exception { // all that is set by reflection, so just make code coverage be happy final Checker checker = new Checker(); checker.setClassLoader(getClass().getClassLoader()); checker.setClassloader(getClass().getClassLoader()); checker.setBasedir("some"); checker.setSeverity("ignore"); PackageObjectFactory factory = new PackageObjectFactory( new HashSet<String>(), Thread.currentThread().getContextClassLoader()); checker.setModuleFactory(factory); checker.setFileExtensions((String[]) null); checker.setFileExtensions(".java", "xml"); try { checker.setCharset("UNKNOWN-CHARSET"); fail("Exception is expected"); } catch (UnsupportedEncodingException ex) { assertEquals("unsupported charset: 'UNKNOWN-CHARSET'", ex.getMessage()); } }
@Test public void testFinishLocalSetupFullyInitialized() throws Exception { final Checker checker = new Checker(); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); PackageObjectFactory factory = new PackageObjectFactory( new HashSet<String>(), Thread.currentThread().getContextClassLoader()); checker.setModuleFactory(factory); checker.finishLocalSetup(); }
@Test public void testSetupChildListener() throws Exception { final Checker checker = new Checker(); PackageObjectFactory factory = new PackageObjectFactory( new HashSet<String>(), Thread.currentThread().getContextClassLoader()); checker.setModuleFactory(factory); Configuration config = new DefaultConfiguration(DebugAuditAdapter.class.getCanonicalName()); checker.setupChild(config); }
@Override public int compare(String node1, String node2) { String[] n1 = Checker.splitNodeAndDegree(node1); String[] n2 = Checker.splitNodeAndDegree(node2); int deg1 = Integer.parseInt(n1[1]); int deg2 = Integer.parseInt(n2[1]); if (Checker.DoubleCheck(n1[0], deg1, n2[0], deg2)) return -1; return 1; }
@Test public void testNoClassLoaderNoModuleFactory() throws Exception { final Checker checker = new Checker(); try { checker.finishLocalSetup(); fail("Exception is expected"); } catch (CheckstyleException ex) { assertEquals( "if no custom moduleFactory is set, " + "moduleClassLoader must be specified", ex.getMessage()); } }
@Test public void testFileExtensions() throws Exception { final Checker checker = new Checker(); final List<File> files = new ArrayList<>(); File file = new File("file.pdf"); files.add(file); File otherFile = new File("file.java"); files.add(otherFile); final String[] fileExtensions = {"java", "xml", "properties"}; checker.setFileExtensions(fileExtensions); final int counter = checker.process(files); // comparing to 1 as there is only one legal file in input assertEquals(1, counter); }
@Override public <E, T> boolean mapping(Collection<E> col1, Collection<T> col2) { if (Checker.isEmpty(col1) || Checker.isEmpty(col2)) { return false; } acquireReference(); try { return keepMapping(col1, col2) | keepMapping(col2, col1); } catch (Exception e) { e.printStackTrace(); } finally { releaseReference(); } return false; }
@Override public void setAutomaticChecked(Boolean value) { try { Checker.checkIfNotNull(value); switch (this.keepAutomaticChecked()) { case ALWAYS: { this.isAutomaticChecked = true; break; } case NEVER: { this.isAutomaticChecked = false; break; } case CHOICE: { this.isAutomaticChecked = value; break; } default: { break; } } } catch (Exception ex) { throw ex; } }
public Collection<V> values() { Collection<V> copied = new ArrayList<>(); for (V v : map.values()) { copied.add(Checker.copyIfRequired(v)); } return copied; }
/** * Comipla uma expressão textual para uma instância de <code>Expression</code>. * * @param source O código fonte da expressão a ser compilada. * @return A instância de expressão compilada. */ public Expression compile(String source) { // Passo 1 (Parsing) Transforma texto em objetos do tipo Statement try { statementList = parser.parse(source); } catch (ParseException e) { System.err.println(PARSING + source); throw new LangException(E10, e); } catch (CTDException ctde) { System.err.println(PARSING + source); throw new LangException(E10, ctde); } // Passo 2 (Checking) Valida gramática e semântica try { checker.check(statementList); } catch (CTDException ctde) { System.err.println(CHECKING + statementList + debugList()); throw ctde; } // Passo 3 (Linking) Liga os elementos em uma árvore binária try { Statement root = linker.link(statementList); if (root.isLiteral()) { root.result(null); // não precisa de DataContainer } if (root.resultType().equals(BOOLEAN)) { return new BooleanExpression(source, root); } else { return new Expression(source, root); } } catch (CTDException ctde) { System.err.println(LINKING + statementList + debugList()); throw ctde; } }
public Set<K> keySet() { Set<K> copied = new HashSet<>(); for (K k : map.keySet()) { copied.add(Checker.copyIfRequired(k)); } return copied; }
public void testCausale15() { causale = ""; for (int i = 1; i <= 250; i++) { causale = causale + "a"; } assertTrue(Checker.checkCausale(danni, causale)); }
@Test public void testSetupChildExceptions() throws Exception { final Checker checker = new Checker(); PackageObjectFactory factory = new PackageObjectFactory( new HashSet<String>(), Thread.currentThread().getContextClassLoader()); checker.setModuleFactory(factory); Configuration config = new DefaultConfiguration("java.lang.String"); try { checker.setupChild(config); fail("Exception is expected"); } catch (CheckstyleException ex) { assertEquals("java.lang.String is not allowed as a child in Checker", ex.getMessage()); } }
public void setPosition(Integer position) { try { Checker.checkIfIntegerNotLessZero(position); this.position = position; } catch (Exception ex) { throw ex; } }
@Override public void setAutomaticPlay(Boolean value) { try { Checker.checkIfNotNull(value); isAutomaticPlay = value; } catch (Exception ex) { throw ex; } }
@Override public void setSpeed(Integer value) { try { Checker.checkIfNotNull(value); speed = value; } catch (Exception ex) { throw ex; } }
@Override public void setHeight(Integer height) { try { Checker.checkIfNotNull(height); this.height = height; this.updateSize(); } catch (Exception ex) { throw ex; } }
@Override public void setSize(Integer height, Integer width) { try { Checker.checkIfNotNull(height); Checker.checkIfNotNull(width); int widthOld = this.width.intValue(); int heightOld = this.height.intValue(); int widthNew = width.intValue(); int heightNew = height.intValue(); if ((widthOld != widthNew) || (heightOld != heightNew)) { this.height = height; this.width = width; this.updateSize(); this.updateViews(); } } catch (Exception ex) { throw ex; } }
@Override public void setStatus(EnumVisualizationStatus status) { try { Checker.checkIfNotNull(status); this.status = status; this.updateViews(); } catch (Exception ex) { throw ex; } }
@Override public void setSurface(EnumSurface surface) { try { Checker.checkIfNotNull(surface); this.surface = surface; this.updateViews(); } catch (Exception ex) { throw ex; } }
private void getNextElement() { if (iterator.hasNext()) { nextElement = iterator.next(); if (!checker.check(nextElement)) { getNextElement(); } } else { nextElement = null; } }
@Override public void setWidth(Integer width) { try { Checker.checkIfNotNull(width); this.width = width; this.updateSize(); } catch (Exception ex) { throw ex; } }
public void onModuleLoad() { /** * Предположим, что в системе есть 2-а компонента: 1. компонент проверки (отвечает за проверку * нового пожелания) - отправляет события когда приходят новые пожелания 2. компонент * отображения (отвечающий за отображение пожелания) - получает эти события */ Checker checker = new Checker(); ShowingWidget widget = new ShowingWidget(); // define event receivers and register themselves in event senders checker.addSmileReceivedEventHandler(widget); checker.newSmileReceived(); RootPanel.get().add(widget); // SimpleEventBus eventBus = new SimpleEventBus(); // SmileReceiver receiverSmile = new SmileReceiver(eventBus); // eventBus.fireEvent(new SmileReceivedEvent("Smile today and everyday! ^__^")); // RootPanel.get().add(receiverSmile); }
@Test public void testCacheFile() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class); final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class); treeWalkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath()); treeWalkerConfig.addChild(checkConfig); final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration"); checkerConfig.addAttribute("charset", "UTF-8"); checkerConfig.addChild(treeWalkerConfig); final Checker checker = new Checker(); final Locale locale = Locale.ROOT; checker.setLocaleCountry(locale.getCountry()); checker.setLocaleLanguage(locale.getLanguage()); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); checker.configure(checkerConfig); checker.addListener(new BriefLogger(stream)); final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath(); final String[] expected = {}; verify(checker, pathToEmptyFile, pathToEmptyFile, expected); // one more time to reuse cache verify(checker, pathToEmptyFile, pathToEmptyFile, expected); }
public static void main(String[] args) throws Exception { BeanInfo i = Introspector.getBeanInfo(C.class, Object.class); Checker.checkEq("description", i.getBeanDescriptor().getShortDescription(), "CHILD"); PropertyDescriptor[] pds = i.getPropertyDescriptors(); Checker.checkEq("number of properties", pds.length, 1); PropertyDescriptor p = pds[0]; Checker.checkEq("property description", p.getShortDescription(), "CHILDPROPERTY"); Checker.checkEq("isBound", p.isBound(), childFlag); Checker.checkEq("isExpert", p.isExpert(), childFlag); Checker.checkEq("isHidden", p.isHidden(), childFlag); Checker.checkEq("isPreferred", p.isPreferred(), childFlag); Checker.checkEq("required", p.getValue("required"), childFlag); Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), childFlag); Checker.checkEnumEq( "enumerationValues", p.getValue("enumerationValues"), new Object[] {"BOTTOM", 3, "javax.swing.SwingConstants.BOTTOM"}); }
/** 构建查询语句 */ public SQLStatement createStatement() { if (clazz == null) { throw new IllegalArgumentException( "U Must Set A Query Entity Class By queryWho(Class) or " + "QueryBuilder(Class)"); } if (Checker.isEmpty(group) && !Checker.isEmpty(having)) { throw new IllegalArgumentException( "HAVING仅允许在有GroupBy的时候使用(HAVING clauses are only permitted when using a groupBy clause)"); } if (!Checker.isEmpty(limit) && !limitPattern.matcher(limit).matches()) { throw new IllegalArgumentException("invalid LIMIT clauses:" + limit); } StringBuilder query = new StringBuilder(120); query.append(SELECT); if (distinct) { query.append(DISTINCT); } if (!Checker.isEmpty(columns)) { appendColumns(query, columns); } else { query.append(ASTERISK); } query.append(FROM).append(getTableName()); query.append(whereBuilder.createWhereString()); appendClause(query, GROUP_BY, group); appendClause(query, HAVING, having); appendClause(query, ORDER_BY, order); appendClause(query, LIMIT, limit); SQLStatement stmt = new SQLStatement(); stmt.sql = query.toString(); stmt.bindArgs = whereBuilder.transToStringArray(); return stmt; }
private void tryConnect() throws IOException { if (mode == MODE_SELF) { jmxc = null; conn = ManagementFactory.getPlatformMBeanServer(); } else { if (mode == MODE_LOCAL) { if (!lvm.isManageable()) { lvm.startManagementAgent(); if (!lvm.isManageable()) { // FIXME: what to throw throw new IOException(lvm + " not manageable"); // NOI18N } } if (jmxUrl == null) { jmxUrl = new JMXServiceURL(lvm.connectorAddress()); } } Map<String, Object> env = new HashMap(); if (envProvider != null) env.putAll(envProvider.getEnvironment(app, app.getStorage())); if (userName != null || password != null) env.put(JMXConnector.CREDENTIALS, new String[] {userName, password}); if (!insecure && mode != MODE_LOCAL && env.get(JMXConnector.CREDENTIALS) != null) { env.put("jmx.remote.x.check.stub", "true"); // NOI18N checkSSLStub = true; } else { checkSSLStub = false; } jmxc = JMXConnectorFactory.newJMXConnector(jmxUrl, env); jmxc.addConnectionNotificationListener(this, null, null); try { jmxc.connect(env); } catch (java.io.IOException e) { // Likely a SSL-protected RMI registry if ("rmi".equals(jmxUrl.getProtocol())) { // NOI18N env.put("com.sun.jndi.rmi.factory.socket", sslRMIClientSocketFactory); // NOI18N jmxc.connect(env); } else { throw e; } } MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); conn = Checker.newChecker(this, mbsc); } isDead = false; }