id
stringlengths
36
36
text
stringlengths
1
1.25M
fada4bf1-9a76-4688-a74d-446b536de15a
public void setWeight(Integer weight) { this.weight = weight; }
df6b01cf-1029-444b-8968-c295efe5a53a
public Main() { root = new Node("SeaMe"); Project gamification = new Project("gamification"); root.addChild(new Person("npelloux")); root.addChild(new Person("scauch")); root.addChild(new Person("jLeclert")); }
cda107de-63ee-4b6e-9ea1-3cdcb4b463ea
public static void main(String[] args) throws Exception { int port = Integer.parseInt(System.getenv("PORT")); HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); server.createContext("/", new HttpHandler() { final Main main = new Main(); @Override public void handle(HttpExchange exchange) throws IOException { String body = ""; if ("/update".equals(exchange.getRequestURI().getPath())) { // main.updateQuality(); } else { body = itemsAsJson(); String query = exchange.getRequestURI().getQuery(); if (null != query) { String callback = query.split("[&=]")[1]; body = callback + "(" + body + ")"; } } byte[] response = body.getBytes(); exchange.sendResponseHeaders(200, response.length); exchange.getResponseBody().write(response); exchange.close(); } private String itemsAsJson() { return main.getRoot().toJson(); } }); server.start(); }
c30df024-4a2d-439b-84d0-e10c1a1b7255
@Override public void handle(HttpExchange exchange) throws IOException { String body = ""; if ("/update".equals(exchange.getRequestURI().getPath())) { // main.updateQuality(); } else { body = itemsAsJson(); String query = exchange.getRequestURI().getQuery(); if (null != query) { String callback = query.split("[&=]")[1]; body = callback + "(" + body + ")"; } } byte[] response = body.getBytes(); exchange.sendResponseHeaders(200, response.length); exchange.getResponseBody().write(response); exchange.close(); }
1b855062-e626-4035-9345-c4a06dfcbb18
private String itemsAsJson() { return main.getRoot().toJson(); }
a0ee3656-2a68-4a9e-b335-8427c9a58a8b
public Node getRoot() { return root; }
5ee05865-1acf-4f1d-a03d-80c4fcd4d2c6
public void setRoot(Node root) { this.root = root; }
601824d4-2d2a-48cc-a8b5-7a5303a0755c
public Project(String name){ super(name); }
0696eafc-fad4-43ca-9879-53e49d5b3af5
@BeforeMethod public void setUp() throws Exception { }
11054a02-cb43-48d3-8de0-b80b7c27e5c7
@Test public void shouldCreateObject() { Node node = new Node("testNode"); assertThat(node).isNotNull(); }
58bd3ac7-facc-4acb-a0f4-e71817f72c4a
@Test public void shouldBeAbleToAddChild() { Node parent = new Node("parent"); Node child = new Node("child"); parent.addChild(child); assertThat(parent.getChild(0)).isNotNull(); }
4070547d-4d59-454b-ab52-a61f3af68276
@Test public void shouldWriteValidJson() { Node parent = new Node("parent"); Node child = new Node("child"); parent.addChild(child); assertThat(parent.toJson()).isEqualTo("[{\"name\":\"parent\"}]"); }
97cecfd6-376e-4091-b42b-2bd59532bc40
public static void main(String args[]) { Injector injector = Guice.createInjector(new JeneverModule()); injector.getInstance(Jenever.class).parseArgs(args); }
a4c960d9-abc7-4cbf-9ecc-27e8935f1aff
@Inject public Jenever(JeneverOptions jo, JeneverOptionsHandler joh) { this.jo = jo; this.handler = joh; }
f9bcd0df-9feb-4108-87cf-64597dfea715
public void parseArgs(String[] args) { Options options = new Options(); for (Option o : jo.options) { options.addOption(o); } CommandLine parser; try { parser = new GnuParser().parse(options, args); } catch (ParseException e) { log.info("Unable to parse options."); return; } if (parser.hasOption("help") || parser.getOptions().length == 0) { new HelpFormatter().printHelp("jen <args>", "jenever - A package manager for java", options, ""); System.exit(0); } else if (parser.hasOption("init")) { handler.checkParamsSet(); } else { handler.checkParamsSet(); handler.handle(parser); } }
a774ff68-895e-4f41-a90c-0e792841aac7
@Inject public FileSystem(JeneverOptions options) { this.options = options; }
3a75a657-802e-4244-94e7-8327299cc409
public void makeLibs(String envName) { final File file = new File("lib"); log.info("Creating lib folder at {}",file.getAbsolutePath()); if (file.exists()) { log.info("File called 'lib' already exists, aborting"); return; } file.mkdir(); log.info("Successfully created folder, copying jars."); final File jarDir; if (null == envName) { jarDir = new File(options.jenEnv); } else { jarDir = new File(options.jenHome+File.separator+envName); } for (final File jar : jarDir.listFiles()) { if (!jar.getName().endsWith(".jar")) continue; log.info("Copying {}",jar.getName()); try { Files.copy(jar, new File(file.getAbsolutePath()+File.separator+jar.getName())); } catch (IOException e) { log.error("Error copying across {}, ignoring.",jar.getName()); } } log.info("Lib folder generation complete"); }
75c47061-267b-4cbf-ad87-72be2600375a
public void makeManifest(String envName) { final File manifestFile = new File("libs.txt"); log.info("Creating manifest file at {}",manifestFile.getAbsolutePath()); if (manifestFile.exists()) { log.info("File called 'libs.txt' already exists, aborting"); return; } try { manifestFile.createNewFile(); } catch (IOException e) { log.error("Unable to create file, aborting"); log.error("Exception: {}",e); return; } log.info("Successfully created file, inserting manifest."); final File jarDir; if (null == envName) { jarDir = new File(options.jenEnv); } else { jarDir = new File(options.jenHome+File.separator+envName); } Set<String> jarNames = new HashSet<String>(); for (final File jar : jarDir.listFiles()) { if (!jar.getName().endsWith(".jar")) continue; log.debug("Adding {} to manifest",jar.getName()); jarNames.add(jar.getName()); } try { log.debug("Writing to file."); Files.write(Joiner.on("\n").join(jarNames).getBytes(), manifestFile); } catch (IOException e) { log.error("Unable to write to file, aborting"); log.error("Exception: {}",e); } log.info("Manifest generation complete"); }
9f6e2401-22cf-405c-aff8-c3afbe396c5f
@Inject public JeneverOptionsHandler(JeneverOptions jo, PackageDownloader jd, FileSystem fs) { this.options = jo; this.jd = jd; this.fs = fs; }
54400d12-6887-4134-8d99-1b25fdf587b8
@SuppressWarnings("static-access") public void handle(CommandLine parser) { //Handle listing files if (parser.hasOption("ls")) { final File jenHome = new File(options.jenHome); if (jenHome.listFiles().length == 0) { log.info("No jen environments found."); return; } for (File f : jenHome.listFiles()) { log.info("{}",f.getName()); } } //Increase verbosity if (parser.hasOption("v")) { ch.qos.logback.classic.Logger log = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(this.log.ROOT_LOGGER_NAME); log.setLevel(Level.DEBUG); } //Decrease verbosity if (parser.hasOption("q")) { ch.qos.logback.classic.Logger log = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(this.log.ROOT_LOGGER_NAME); log.setLevel(Level.ERROR); } //Install packages if (parser.hasOption("i")) { jd.process(parser.getOptionValues("i")); } //Change environment if (parser.hasOption("e")) { log.debug("Attempting to change environment to {}",parser.getOptionValues("e")); writeConfig(parser.getOptionValues("e")); log.info("Succesfully changed environment to {}",parser.getOptionValue("e")); } if (parser.hasOption("l")) { fs.makeLibs(parser.getOptionValue("l")); } if (parser.hasOption("m")) { fs.makeManifest(parser.getOptionValue("m")); } }
039993c4-64a6-49a2-a61d-a07e05b75542
public void checkParamsSet() { if (!new File(options.jenHome).exists()) { log.info("Cannot find JEN_HOME directory at {} - creating...", options.jenHome); try { log.debug("Creating file ... "); final File file = new File(options.jenHome); file.mkdir(); log.info("Successfully created environment directory at {}",options.jenEnv); } catch (Exception e) { log.error("Error: could not create file at {}, exiting.",options.jenEnv); log.error("{}",e); System.exit(-1); } } if (!new File(options.jenEnv).exists()) { log.info("Cannot find current environment directory at {} - creating...", options.jenEnv); try { log.debug("Creating file ... "); final File file = new File(options.jenEnv); file.mkdir(); log.info("Successfully created environment directory at {}",options.jenEnv); } catch (Exception e) { log.error("Error: could not create file at {}, exiting.",options.jenEnv); log.error("{}",e); System.exit(-1); } } writeConfig(new String[] { "default" }); }
8c4ac536-f7eb-4d8a-af0e-ff6f00683235
public void writeConfig(String[] env) { String filename; String contents; if (System.getProperty("os.name").startsWith("Windows")) { filename = "config.bat"; contents = String.format("set JEN_ENV=%s", env[0]); } else if (System.getProperty("os.name").startsWith("Linux")) { filename = "config"; contents = String.format("export JEN_ENV=%s", env[0]); } else { //Handle other os here return; } try { Files.write(contents.getBytes(), new File(options.jenHome+File.separator+filename)); } catch (IOException e) { log.error("Could not write to config file - {}",e); } }
b5100d21-ea0e-45cb-90a4-aaad6ecca248
@Override protected void configure() { bind(Jenever.class); bind(JeneverOptionsHandler.class); bind(PackageDownloader.class); bind(JeneverOptions.class); bind(FileSystem.class); bind(PomParser.class).to(DefaultDomParser.class); }
051f0750-8c5b-4f62-83f2-afc0f7290e87
@Inject public DefaultDomParser(JeneverOptions jo) { this.options = jo; }
3a5775ec-1ab9-4658-967d-a4b11390604e
public List<Package> getDependencies(Package p) { final String pom = p.artifactId+"-"+p.version+".pom"; final String path = p.groupId.replaceAll("\\.", "/"); final String url = Joiner.on("/").join(new String[] { options.BASE_URL, path, p.artifactId, p.version, pom }); Document doc; try { log.debug("Attempting to parse xml file at {}",url); doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new URL(url).openStream()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { log.error("File does not exist at {}",url); return null; } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } XPath xpath = XPathFactory.newInstance().newXPath(); NodeList links; try { links = (NodeList) xpath.evaluate("//dependencies/dependency[not(scope)]", doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } List<Package> deps = new ArrayList<Package>(); for (int i = 0; i < links.getLength(); i++) { Package pa = nodeToPackage(links.item(i)); if (pa != null) { deps.add(pa); } } return deps; }
082cd45c-0a9f-4d5f-9d88-e483374b3613
private Package nodeToPackage(Node item) { Package p = new Package(); NodeList params = item.getChildNodes(); for (int i = 0; i < params.getLength(); i++) { Node current = params.item(i); if (current instanceof Element) { if (current.getNodeName().equals("groupId")) { p.groupId = current.getFirstChild().getNodeValue(); } if (current.getNodeName().equals("artifactId")) { p.artifactId = current.getFirstChild().getNodeValue(); } if (current.getNodeName().equals("version")) { p.version = current.getFirstChild().getNodeValue(); } } } if (p.groupId.contains("${") || p.artifactId.contains("${") || p.version.contains("${")) { return null; } return p; }
a927752e-357b-4f85-9427-6a613ca59aa9
public String mostRecentVersion(Package p) { String path = p.groupId.replaceAll("\\.", "/"); String url = Joiner.on("/").join(new String[] { options.BASE_URL, path , p.artifactId, "maven-metadata.xml" }); Document doc; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new URL(url).openStream()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { log.error("File does not exist at {}",url); return null; } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } XPath xpath = XPathFactory.newInstance().newXPath(); NodeList links; try { links = (NodeList) xpath.evaluate("//versioning/release", doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return links.item(links.getLength()-1).getChildNodes().item(0).getNodeValue(); }
61726fea-c88c-433e-96d6-d82b2d88f49d
@Inject public PackageDownloader(JeneverOptions jo, PomParser parser) { this.options = jo; this.parser = parser; }
097a6cbb-e780-4c11-9dee-bd0dea9e1f67
public void process(String[] optionValues) { for(String packageString : optionValues) { try { log.info("Processing: {}",packageString); downloadPackage(new Package().setSignature(packageString)); log.info(""); } catch (IOException e) { log.info("Could not download package {}, exiting...",packageString); System.exit(1); } } }
85e267a1-7c0b-430b-88bd-7aa7779f8355
public void downloadPackage(Package p) throws IOException { if (p.version == null) { p.version = parser.mostRecentVersion(p); } final List<Package> deps; try { deps = parser.getDependencies(p); } catch (RuntimeException e) { log.error("Error: Unable to resolve package data from {}, aborting.",p.toString()); return; } if (deps.size() > 0) { log.info("{} has {} dependencies, resolving...",p.toString(),deps.size()); for(Package dependency : deps) { downloadPackage(dependency); } } log.info("Downloading {} ...",p.toString()); String downloadUrl = getDownloadUrl(p); URL jarRequest = new URL(downloadUrl); ReadableByteChannel rbc = Channels.newChannel(jarRequest.openStream()); FileOutputStream fos = new FileOutputStream(options.jenEnv+File.separator+p.artifactId+"-"+p.version+".jar"); fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.close(); log.info("Download complete."); }
8298694b-8b26-4bd8-98cd-30a7c4d40088
private String getDownloadUrl(Package p) { return Joiner.on("/").join(new String[] { options.BASE_URL, p.groupId.replaceAll("\\.", "/"), p.artifactId, p.version, p.artifactId+"-"+p.version+".jar" }); }
f21e98a0-1652-48cb-a5c3-d146180eeb5b
List<Package> getDependencies(Package p);
85bc0209-3cc0-4c23-95d1-98b524039924
String mostRecentVersion(Package p);
0af41070-6d9d-4014-a3e1-c496e26d0305
public Package() { }
3ef5a45a-6653-41b0-bb5e-8fc25902ad4e
public Package setSignature(String string) { String[] splitted = string.split(":"); if (splitted.length >= 2) { this.groupId = splitted[0]; this.artifactId = splitted[1]; } else { this.artifactId = splitted[0]; } if (splitted.length == 3) { this.version = splitted[2]; } else { this.version = null; } return this; }
21465d0e-b8f8-4c5d-9671-29d1e2c67ce4
@Override public String toString() { String name = artifactId; if (groupId != null) { name = groupId+"."+name; } if (version != null) { name = name+"-"+version; } return name; }
dcd3f8a8-1efb-418e-9105-307476eb4391
@Test public void testCanonicalName() { String[] params = new String[]{"foo.bar","baz","1.0"}; Package p = new Package().setSignature(Joiner.on(":").join(params)); assertEquals(p.groupId,params[0]); assertEquals(p.artifactId,params[1]); assertEquals(p.version, params[2]); assertEquals(p.toString(),"foo.bar.baz-1.0"); }
68667fbd-45b4-44c6-b108-a50df516960e
@Test public void testNoVersion() { String[] params = new String[]{"foo.bar","baz"}; Package p = new Package().setSignature(Joiner.on(":").join(params)); assertEquals(p.groupId,params[0]); assertEquals(p.artifactId,params[1]); assertEquals(p.version, null); assertEquals(p.toString(),"foo.bar.baz"); }
7acc03f0-9510-4e7b-ae7a-a341bb22c6c3
@Test public void testJustArtifact() { String[] params = new String[]{"baz"}; Package p = new Package().setSignature(Joiner.on(":").join(params)); assertEquals(p.groupId,null); assertEquals(p.artifactId,params[0]); assertEquals(p.version, null); assertEquals(p.toString(),"baz"); }
00bffe02-f716-4269-9c44-113502aec6d4
public void setValue(String path) { this.value = path; }
5c9b264b-b656-4e2c-b1fc-95351c6404e7
public void add(String name) { value += PATH_SEPARATOR + name; }
3266c9ee-cb20-4925-a3c0-06b8d4e29fc4
public String getValue() { return value; }
f0b8e3ef-164d-4e7f-ae79-2d8931432b01
public UrlDocument() { }
3aa4dfd9-6cac-4a9a-9baf-cc65c1dc1635
public UrlDocument(String name, String url, TreeNode parent) { setName(name); setUrl(url); setParentNode(parent); pathUpdate(); }
9063c886-c2b1-40aa-bdee-66f1208b5378
public void pathUpdate() { Path fullPathProxy = new Path(); Path parentPathProxy = new Path(); if (isTop()) { parentPathProxy.setValue(null); fullPathProxy.setValue(null); } else { if (isRoot()) { parentPathProxy.setValue(""); fullPathProxy.setValue(name); } else { UrlDocument parentDoc = (UrlDocument) getParentNode().getData(); parentPathProxy.setValue(parentDoc.getFullPath()); fullPathProxy.setValue(parentPathProxy.getValue()); fullPathProxy.add(name); } } fullPath = fullPathProxy.getValue(); parentPath = parentPathProxy.getValue(); }
8e6e8605-fae6-41d0-b67e-330d35f31909
public String getFullPath() { return fullPath; }
8e112d6b-e4c3-44f9-a235-86ae050a24d9
public void setFullPath(String path) { this.fullPath = path; }
3f3fa657-bbdf-4894-961a-5d62049a8a4a
public boolean isRoot() { return getParentNode().getParent() == null; }
43a3a137-ea36-4225-84d7-a136e2661c88
public boolean isTop() { return getParentNode() == null; }
b6d97131-650d-42f9-ad08-c9bbc8549af1
public String getName() { return name; }
9ba5dab7-fd09-4aa3-b65b-13230a608fc9
public void setName(String name) { this.name = name; pathUpdate(); }
a1a67765-b4b3-4bda-b776-965517e7398a
public String getUrl() { return url; }
8e4d4cac-7146-4f15-9d70-925de912a501
public void setUrl(String url) { this.url = url; }
cecd2d7d-6dec-4652-813b-1fc2d5a944ed
public TreeNode getParentNode() { return parentNode; }
aafc8fef-661c-4285-9a32-feb336ac4d9f
public void setParentNode(TreeNode node) { this.parentNode = node; }
c2b5cfef-fa68-4080-982a-8f72077d2024
public String getParentPath() { return parentPath; }
fda29ba5-7954-4261-bcd1-f26e6a0a1c53
public void setParentPath(String parentPath) { this.parentPath = parentPath; }
e330a478-d623-45d5-9704-d37e9b469eb6
@Override public String toString() { return fullPath; }
2f5b05ac-f339-4762-b59f-92f5af0bf766
public TreeController() { root = new DefaultTreeNode(new UrlDocument("Base", "about:blank", (TreeNode) null), (TreeNode) null); DefaultTreeNode top = new DefaultTreeNode(new UrlDocument("Root", "about:blank", root), root); selectedNode = top; nodePath = "/Root"; DefaultTreeNode folder1 = new DefaultTreeNode(new UrlDocument( "Newspapers", "about:blank", top), top); new DefaultTreeNode(new UrlDocument("libe", "http://www.liberation.fr", folder1), folder1); new DefaultTreeNode(new UrlDocument("lemonde", "http://www.lemonde.fr", folder1), folder1); DefaultTreeNode folder2 = new DefaultTreeNode(new UrlDocument( "Web Design", "about:blank", top), top); new DefaultTreeNode(new UrlDocument("w3schools", "http://www.w3schools.com/", folder2), folder2); new DefaultTreeNode(new UrlDocument("primefaces", "http://www.primefaces.org/showcase/ui/home.jsf", folder2), folder2); new DefaultTreeNode(new UrlDocument("prettyfaces", "http://ocpsoft.org/docs/prettyfaces/3.3.2/en-US/html_single/", folder2), folder2); }
e588e1e4-c633-4dfb-a631-d01eeaa5a625
public void setSelectedNode(TreeNode selectedNode) { this.selectedNode.setSelected(false); this.selectedNode = (DefaultTreeNode) selectedNode; this.selectedNode.setSelected(true); }
18464aca-0924-474b-a9b8-ea73946caa38
public String displayNode() { String[] path = getNodePath().split("/"); expandTree(root, path); return null; }
05c52d05-16a2-42d0-be20-763e443ccad8
private void expandTree(TreeNode start, String[] path) { for (String item : path) { for (TreeNode node : start.getChildren()) { UrlDocument doc = (UrlDocument) node.getData(); if (doc.getName().matches(item)) { node.getParent().setExpanded(true); start = node; break; } } } setSelectedNode(start); UrlDocument doc = (UrlDocument) start.getData(); displayDoc.setDoc(doc); crudDoc.setTreeControl(this); crudDoc.setDoc(doc); }
82355442-d9f3-414a-afce-8dc9438d6725
public TreeNode getRoot() { return root; }
0c74dbed-70b6-4d1b-ab47-72ad4a40057a
public void setRoot(TreeNode node) { root = node; }
972a6e22-e798-49a5-b6bd-9f554971a340
public TreeNode getSelectedNode() { return selectedNode; }
87a669af-44bb-4ff3-9d59-bdc17bfc3776
public String getNodePath() { return nodePath; }
91a183d6-0249-4ab3-8f24-eebea431e2e0
public void setNodePath(String nodePath) { this.nodePath = nodePath; }
2b73b33e-d7e6-4e68-b023-b695bfddd668
public DisplayController getDisplayDoc() { return displayDoc; }
a4df985d-dbbd-493d-9e56-b2cd4202f4e9
public void setDisplayDoc(DisplayController displayDoc) { this.displayDoc = displayDoc; }
6af0d596-ba25-4438-959f-d78157b66f6e
public CrudController getCrudDoc() { return crudDoc; }
d7e040ba-e7a2-418c-a515-3bbb720eaf14
public void setCrudDoc(CrudController crudDoc) { this.crudDoc = crudDoc; }
1c316672-1a6f-4749-8436-e8297c4d6092
public String getName() { return name; }
143a374d-87d1-4796-b19a-b5b4e32af67e
public void setName(String name) { this.name = name; }
69203579-e6af-4d89-913f-85ce78eb35fe
public String getUrl() { return url; }
7873892e-0a35-4470-b8a3-7bbb44cd330f
public void setUrl(String url) { this.url = url; }
431e9e5a-a0b8-48ea-a3b9-35623182a49c
public void setDoc(UrlDocument doc) { name = doc.getName(); url = doc.getUrl(); }
68ee3061-85a6-49f6-aada-2baae3aacdb3
public void setTreeControl(TreeController treeControl) { this.treeControl = treeControl; }
4c115c64-26f4-460a-b281-ec508fbb98c3
public void createNode() { TreeNode selectedNode = treeControl.getSelectedNode(); UrlDocument doc = new UrlDocument(name, url, selectedNode); new DefaultTreeNode(doc, selectedNode); treeControl.setNodePath(doc.getFullPath()); }
2b37041c-9bc6-462a-9e02-90c98e9bddeb
public void copyNode() { TreeNode selectedNode = treeControl.getSelectedNode(); clipboard = new DefaultTreeNode(new UrlDocument("Base", "about:blank", (TreeNode) null), (TreeNode) null); duplicateTree(selectedNode, clipboard); }
d9e91b45-2832-4123-9627-5d7cfb2557cc
private void duplicateTree(TreeNode source, TreeNode target) { TreeNode node = duplicateNode(source, target); for (TreeNode item : source.getChildren()) { duplicateTree(item, node); } }
823b6d71-5312-4e62-b091-4729c1401b67
private TreeNode duplicateNode(TreeNode source, TreeNode target) { UrlDocument doc = (UrlDocument) source.getData(); TreeNode node = new DefaultTreeNode(new UrlDocument(doc.getName(), doc.getUrl(), target), target); return node; }
eb71a41b-55a6-427f-938f-d3d6c8764cc0
public void pasteNode() { TreeNode selectedNode = treeControl.getSelectedNode(); TreeNode node = clipboard.getChildren().get(0); boolean duplicated = false; for (TreeNode item : selectedNode.getChildren()) { UrlDocument doc = (UrlDocument) item.getData(); UrlDocument docClipboard = (UrlDocument) node.getData(); if (doc.getName().matches(docClipboard.getName())) { duplicated = true; break; } } if (!duplicated) { node.setParent(selectedNode); UrlDocument urlDocument = (UrlDocument) node.getData(); urlDocument.setParentNode(selectedNode); urlDocument.pathUpdate(); updateChildren(node); treeControl.setNodePath(urlDocument.getFullPath()); } }
873a889b-b349-443c-80c7-423287487df3
public void deleteNode() { TreeNode selectedNode = treeControl.getSelectedNode(); if (selectedNode.getParent() != treeControl.getRoot()) { selectedNode.getChildren().clear(); DefaultTreeNode parent = (DefaultTreeNode) selectedNode.getParent(); parent.getChildren().remove(selectedNode); UrlDocument doc = (UrlDocument) parent.getData(); treeControl.setNodePath(doc.getFullPath()); } }
67f5a980-38df-4bd8-93fa-3e1f865c8a40
public void updateNode() { DefaultTreeNode selectedNode = (DefaultTreeNode) treeControl .getSelectedNode(); TreeNode parent = selectedNode.getParent(); UrlDocument doc = new UrlDocument(name, url, parent); selectedNode.setData(doc); treeControl.setNodePath(doc.getFullPath()); updateChildren(selectedNode); }
59477258-d173-4c11-9915-643d73d971b9
private void updateChildren(TreeNode node) { for (TreeNode item : node.getChildren()) { ((UrlDocument) item.getData()).pathUpdate(); updateChildren(item); } }
d84f44d7-674c-4108-b74c-b32b2d2db142
@Override public String toString() { return name + ": " + url; }
b6a1de50-8b70-43f2-9f9b-f10daea6d74d
public String getName() { return name; }
9c4ea396-f673-4831-8d77-df4a00ee6e6d
public String getUrl() { return url; }
40650273-74e3-481b-a314-7885378a3a10
public String getFullPath() { return fullPath; }
4713cd72-6349-4a1b-9235-2612b56a00df
public void setDoc(UrlDocument doc) { this.doc = doc; name = doc.getName(); url = doc.getUrl(); fullPath = doc.getFullPath(); }
11817553-6096-43ab-ab00-7cd3a5360f1b
@Override public String toString() { return doc.getFullPath(); }
f7eb6e4f-31cd-4a49-995c-90d1bdc22976
@Test public void getValidateCardMethod() { Card card = mock(Card.class); Account acc = mock(Account.class); ATM atm = new ATM(acc, card); card.isBlocked(); atm.validateCard(); verify(card, atLeastOnce()).isBlocked(); }
67cdde76-2a8a-4bbb-a3b4-25dcd51c233b
@Test public void ValidateCardParametr() { Card card = mock(Card.class); Account acc = mock(Account.class); ATM atm = new ATM(acc, card); when(card.isBlocked()).thenReturn(true); boolean result = atm.validateCard(); assertEquals(true, result); }
7f6e3f8b-ec93-4768-987c-a5aea1317ddf
@Test public void getValidatePinCodeMethod() { Card card = mock(Card.class); Account acc = mock(Account.class); ATM atm = new ATM(acc, card); card.checkPin(1234); atm.validatePincode(1234); verify(card, atLeastOnce()).checkPin(1234); }
869101e4-75d3-4daa-845d-8b28b98d3a4c
@Test public void PinCodeParametr() { Card card = mock(Card.class); Account acc = mock(Account.class); ATM atm = new ATM(acc, card); when(card.checkPin(1234)).thenReturn(true); boolean result = atm.validatePincode(1234); assertEquals(true, result); }
6c1ffb31-ab45-43ee-9dbc-27da794b5701
@Test(expected = NoCardInserted.class) public void checkIfCardIsNotBlockedThrowsException() throws NoCardInserted { Card card = mock(Card.class); Account acc = mock(Account.class); ATM atm = new ATM(acc, card); when(card.isBlocked()).thenReturn(true); atm.checkValidCard(card,1234); }
2d9ddc7b-5d16-4cc5-89d1-c62aba7c8e9e
@Test(expected = NoCardInserted.class) public void checkIfPincodeCorrectThrowsException() throws NoCardInserted { Card card = mock(Card.class); Account acc = mock(Account.class); ATM atm = new ATM(acc, card); when(card.checkPin(1234)).thenReturn(true); atm.checkValidCard(card, 2345); }
109bb950-c86a-434e-bc45-346ca9cee2fc
@Test public void getGettingBalanceMethod() { Account acc = mock(Account.class); Card card = mock(Card.class); ATM atm = new ATM(acc, card); when(acc.getBalance()).thenReturn(500.0); atm.getBalance(); verify(acc, atLeastOnce()).getBalance(); }
3323eb23-3443-4d72-ac77-412f9638f42c
@Test public void checkBalanceGetting() { Account acc = mock(Account.class); Card card = mock(Card.class); ATM atm = new ATM(acc, card); when(acc.getBalance()).thenReturn(500.0); double expected = 500; double actual = atm.getBalance(); assertEquals(expected, actual, 0.01); }
2ed262db-2b5e-4f41-8ba3-78a283a8f5ca
@Test(expected = NotEnoughMoneyInAccount.class) public void checkGettingAmountFromAccount() throws NotEnoughMoneyInAccount, NotEnoughMoneyInATM { Account acc = mock(Account.class); Card card = mock(Card.class); ATM atm = new ATM(acc, card); double ammount = 500.0; double accountBalance = 200; double moneyFromATM = 1000; when(acc.getBalance()).thenReturn(accountBalance); atm.getCash(ammount, accountBalance, moneyFromATM); assertEquals(ammount, accountBalance, 0.01); }