diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..6ae94c5a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# workspace metadata +.metadata + +# class files +*/bin/ +*/target/ + +# SWTBot screenshots +*/screenshots/ \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..57989b5e2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,44 @@ +Contributing +============ + +Please refer to the contributor guide for all the details: + +https://wiki.eclipse.org/EGit/GitHub/ContributorGuide + + +Reporting bugs +-------------- + +For anything other than small changes, it's a good idea to open a bug +report for it (in case one doesn't already exist). This gives others the +chance to give input and is useful for tracking. Create one here: + +https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EGit&component=GitHub + + +Submitting changes +------------------ + +We use Gerrit to review all changes by committers or contributors before +they are merged: + +https://git.eclipse.org/r/ + +Make sure you have an account and have set up the `commit-msg` hook +before committing. + +When committing your changes, see the contributor guide or other commits +on what your commit message should include. + +Run the following to push your change for review (with `username` +replaced by your Gerrit username): + + git push ssh://username@git.eclipse.org:29418/egit/egit-github.git HEAD:refs/for/master + +Add the link to the review as a comment on the bug report, so that +people coming from the bug report can find it. + +Then wait for someone to review your change. If there is something to be +corrected, amend your commit and push it again. + +Have fun :). diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..e23ece2c8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,277 @@ +Eclipse Public License - v 2.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE + PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION + OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + + a) in the case of the initial Contributor, the initial content + Distributed under this Agreement, and + + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + where such changes and/or additions to the Program originate from + and are Distributed by that particular Contributor. A Contribution + "originates" from a Contributor if it was added to the Program by + such Contributor itself or anyone acting on such Contributor's behalf. + Contributions do not include changes or additions to the Program that + are not Modified Works. + +"Contributor" means any person or entity that Distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which +are necessarily infringed by the use or sale of its Contribution alone +or when combined with the Program. + +"Program" means the Contributions Distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this Agreement +or any Secondary License (as applicable), including Contributors. + +"Derivative Works" shall mean any work, whether in Source Code or other +form, that is based on (or derived from) the Program and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. + +"Modified Works" shall mean any work in Source Code or other form that +results from an addition to, deletion from, or modification of the +contents of the Program, including, for purposes of clarity any new file +in Source Code form that contains any contents of the Program. Modified +Works shall not include works that contain only declarations, +interfaces, types, classes, structures, or files of the Program solely +in each case in order to link to, bind by name, or subclass the Program +or Modified Works thereof. + +"Distribute" means the acts of a) distributing or b) making available +in any manner that enables the transfer of a copy. + +"Source Code" means the form of a Program preferred for making +modifications, including but not limited to software source code, +documentation source, and configuration files. + +"Secondary License" means either the GNU General Public License, +Version 2.0, or any later versions of that license, including any +exceptions or additional permissions as identified by the initial +Contributor. + +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free copyright + license to reproduce, prepare Derivative Works of, publicly display, + publicly perform, Distribute and sublicense the Contribution of such + Contributor, if any, and such Derivative Works. + + b) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free patent + license under Licensed Patents to make, use, sell, offer to sell, + import and otherwise transfer the Contribution of such Contributor, + if any, in Source Code or other form. This patent license shall + apply to the combination of the Contribution and the Program if, at + the time the Contribution is added by the Contributor, such addition + of the Contribution causes such combination to be covered by the + Licensed Patents. The patent license shall not apply to any other + combinations which include the Contribution. No hardware per se is + licensed hereunder. + + c) Recipient understands that although each Contributor grants the + licenses to its Contributions set forth herein, no assurances are + provided by any Contributor that the Program does not infringe the + patent or other intellectual property rights of any other entity. + Each Contributor disclaims any liability to Recipient for claims + brought by any other entity based on infringement of intellectual + property rights or otherwise. As a condition to exercising the + rights and licenses granted hereunder, each Recipient hereby + assumes sole responsibility to secure any other intellectual + property rights needed, if any. For example, if a third party + patent license is required to allow Recipient to Distribute the + Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + + d) Each Contributor represents that to its knowledge it has + sufficient copyright rights in its Contribution, if any, to grant + the copyright license set forth in this Agreement. + + e) Notwithstanding the terms of any Secondary License, no + Contributor makes additional grants to any Recipient (other than + those set forth in this Agreement) as a result of such Recipient's + receipt of the Program under the terms of a Secondary License + (if permitted under the terms of Section 3). + +3. REQUIREMENTS + +3.1 If a Contributor Distributes the Program in any form, then: + + a) the Program must also be made available as Source Code, in + accordance with section 3.2, and the Contributor must accompany + the Program with a statement that the Source Code for the Program + is available under this Agreement, and informs Recipients how to + obtain it in a reasonable manner on or through a medium customarily + used for software exchange; and + + b) the Contributor may Distribute the Program under a license + different than this Agreement, provided that such license: + i) effectively disclaims on behalf of all other Contributors all + warranties and conditions, express and implied, including + warranties or conditions of title and non-infringement, and + implied warranties or conditions of merchantability and fitness + for a particular purpose; + + ii) effectively excludes on behalf of all other Contributors all + liability for damages, including direct, indirect, special, + incidental and consequential damages, such as lost profits; + + iii) does not attempt to limit or alter the recipients' rights + in the Source Code under section 3.2; and + + iv) requires any subsequent distribution of the Program by any + party to be under a license that satisfies the requirements + of this section 3. + +3.2 When the Program is Distributed as Source Code: + + a) it must be made available under this Agreement, or if the + Program (i) is combined with other material in a separate file or + files made available under a Secondary License, and (ii) the initial + Contributor attached to the Source Code the notice described in + Exhibit A of this Agreement, then the Program may be made available + under the terms of such Secondary Licenses, and + + b) a copy of this Agreement must be included with each copy of + the Program. + +3.3 Contributors may not remove or alter any copyright, patent, +trademark, attribution notices, disclaimers of warranty, or limitations +of liability ("notices") contained within the Program from any copy of +the Program which they Distribute, provided that Contributors may add +their own appropriate notices. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities +with respect to end users, business partners and the like. While this +license is intended to facilitate the commercial use of the Program, +the Contributor who includes the Program in a commercial product +offering should do so in a manner which does not create potential +liability for other Contributors. Therefore, if a Contributor includes +the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and indemnify every +other Contributor ("Indemnified Contributor") against any losses, +damages and costs (collectively "Losses") arising from claims, lawsuits +and other legal actions brought by a third party against the Indemnified +Contributor to the extent caused by the acts or omissions of such +Commercial Contributor in connection with its distribution of the Program +in a commercial product offering. The obligations in this section do not +apply to any claims or Losses relating to any actual or alleged +intellectual property infringement. In order to qualify, an Indemnified +Contributor must: a) promptly notify the Commercial Contributor in +writing of such claim, and b) allow the Commercial Contributor to control, +and cooperate with the Commercial Contributor in, the defense and any +related settlement negotiations. The Indemnified Contributor may +participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those performance +claims and warranties, and if a court requires any other Contributor to +pay any damages as a result, the Commercial Contributor must pay +those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT +PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" +BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF +TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR +PURPOSE. Each Recipient is solely responsible for determining the +appropriateness of using and distributing the Program and assumes all +risks associated with its exercise of rights under this Agreement, +including but not limited to the risks and costs of program errors, +compliance with applicable laws, damage to or loss of data, programs +or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT +PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS +SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST +PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE +EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other software +or hardware) infringes such Recipient's patent(s), then such Recipient's +rights granted under Section 2(b) shall terminate as of the date such +litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of +time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use +and distribution of the Program as soon as reasonably practicable. +However, Recipient's obligations under this Agreement and any licenses +granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted and +may only be modified in the following manner. The Agreement Steward +reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement +Steward has the right to modify this Agreement. The Eclipse Foundation +is the initial Agreement Steward. The Eclipse Foundation may assign the +responsibility to serve as the Agreement Steward to a suitable separate +entity. Each new version of the Agreement will be given a distinguishing +version number. The Program (including Contributions) may always be +Distributed subject to the version of the Agreement under which it was +received. In addition, after a new version of the Agreement is published, +Contributor may elect to Distribute the Program (including its +Contributions) under the new version. + +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient +receives no rights or licenses to the intellectual property of any +Contributor under this Agreement, whether expressly, by implication, +estoppel or otherwise. All rights in the Program not expressly granted +under this Agreement are reserved. Nothing in this Agreement is intended +to be enforceable by any entity that is not a Contributor or Recipient. +No third-party beneficiary rights are created under this Agreement. + +Exhibit A - Form of Secondary Licenses Notice + +"This Source Code may also be made available under the following +Secondary Licenses when the conditions for such availability set forth +in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), +version(s), and exceptions or additional permissions here}." + + Simply including a copy of this Agreement, including this Exhibit A + is not sufficient to license the Source Code under Secondary Licenses. + + If it is not possible or desirable to put the notice in a particular + file, then You may include the notice in a location (such as a LICENSE + file in a relevant directory) where a recipient would be likely to + look for such a notice. + + You may add additional accurate notices of copyright ownership. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..28bfd9a01 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +Eclipse EGit Github Connector +============================= + +EGit Github Connector is an Eclipse plugin for working with Git repositories +hosted on Github. It is based on the JGit library, which is a Git implementation +in pure Java and integrates with EGit which is the Eclipse Git Team Provider. + +This package is licensed under the EPL. Please refer to the LICENSE file +for the complete license. + +Compatibility +------------- + +- In general, EGit supports at least the latest two Eclipse releases. + For details, please see https://wiki.eclipse.org/EGit/FAQ + +- Newer version of EGit may implement new functionality, remove + existing functions and change others without other notice than what + is written in the commit log and source files themselves. + +Support +------- + +Post question or comments to the egit-dev@eclipse.org mailing list. +You need to be subscribed to post, see here: + +https://dev.eclipse.org/mailman/listinfo/egit-dev + +Bugs are tracked in [Bugzilla](https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&classification=Technology&component=GitHub&list_id=11227256&product=EGit&query_format=advanced) + +Create new bugs [here](https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EGit;component=GitHub) + + +Contributing +------------ + +**This project does not use pull requests.** +Pull requests to this GitHub repository will be ignored. + +Push patches to Gerrit at https://git.eclipse.org/r/egit/egit-github as explained +in the Contributor Guide: + +https://wiki.eclipse.org/EGit/GitHub/ContributorGuide + + +About Git +--------- + +More information about Git, its repository format, and the canonical +C based implementation can be obtained from the Git websites: + +http://git-scm.com/ diff --git a/org.eclipse.egit.github.core.tests/.classpath b/org.eclipse.egit.github.core.tests/.classpath new file mode 100644 index 000000000..f04af4e18 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/org.eclipse.egit.github.core.tests/.project b/org.eclipse.egit.github.core.tests/.project new file mode 100644 index 000000000..707737606 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.egit.github.core.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.egit.github.core.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..87b7a7a3a --- /dev/null +++ b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/org.eclipse.egit.github.core.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 000000000..a197ae5fb --- /dev/null +++ b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,62 @@ +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +org.eclipse.jdt.ui.text.custom_code_templates= +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=false +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/org.eclipse.egit.github.core.tests/.settings/org.eclipse.mylyn.team.ui.prefs b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.mylyn.team.ui.prefs new file mode 100644 index 000000000..2fca43227 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.mylyn.team.ui.prefs @@ -0,0 +1,3 @@ +#Tue Jul 19 20:11:28 CEST 2011 +commit.comment.template=${task.description}\n\nBug\: ${task.key} +eclipse.preferences.version=1 diff --git a/org.eclipse.egit.github.core.tests/.settings/org.eclipse.pde.prefs b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.pde.prefs new file mode 100644 index 000000000..2174e4fd5 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/.settings/org.eclipse.pde.prefs @@ -0,0 +1,34 @@ +compilers.f.unresolved-features=1 +compilers.f.unresolved-plugins=1 +compilers.incompatible-environment=1 +compilers.p.build=1 +compilers.p.build.bin.includes=1 +compilers.p.build.encodings=2 +compilers.p.build.java.compiler=2 +compilers.p.build.java.compliance=1 +compilers.p.build.missing.output=2 +compilers.p.build.output.library=1 +compilers.p.build.source.library=1 +compilers.p.build.src.includes=1 +compilers.p.deprecated=1 +compilers.p.discouraged-class=1 +compilers.p.internal=1 +compilers.p.missing-packages=2 +compilers.p.missing-version-export-package=2 +compilers.p.missing-version-import-package=2 +compilers.p.missing-version-require-bundle=2 +compilers.p.no-required-att=0 +compilers.p.no.automatic.module=1 +compilers.p.not-externalized-att=2 +compilers.p.service.component.without.lazyactivation=1 +compilers.p.unknown-attribute=1 +compilers.p.unknown-class=1 +compilers.p.unknown-element=1 +compilers.p.unknown-identifier=1 +compilers.p.unknown-resource=1 +compilers.p.unresolved-ex-points=0 +compilers.p.unresolved-import=0 +compilers.s.create-docs=false +compilers.s.doc-folder=doc +compilers.s.open-tags=1 +eclipse.preferences.version=1 diff --git a/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF b/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF new file mode 100644 index 000000000..93e4352bb --- /dev/null +++ b/org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Automatic-Module-Name: org.eclipse.egit.github.core.tests +Bundle-SymbolicName: org.eclipse.egit.github.core.tests +Bundle-Version: 5.5.0.qualifier +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: com.google.gson;version="[1.6.0,3.0.0]", + com.google.gson.reflect;version="[1.6.0,3.0.0)", + org.eclipse.egit.github.core;version="[5.5.0,5.6.0)", + org.eclipse.egit.github.core.client;version="[5.5.0,5.6.0)", + org.eclipse.egit.github.core.event;version="[5.5.0,5.6.0)", + org.eclipse.egit.github.core.service;version="[5.5.0,5.6.0)", + org.eclipse.egit.github.core.util;version="[5.5.0,5.6.0)", + org.mockito;version="[2.13.0,3.0.0)", + org.mockito.junit;version="2.13.0", + org.mockito.runners;version="[2.13.0,3.0.0)", + org.mockito.stubbing;version="[2.13.0,3.0.0)" +Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)", + org.hamcrest;bundle-version="[1.1.0,2.0.0)", + org.objenesis;bundle-version="[2.6.0,3.0.0)" +Bundle-Vendor: %Bundle-Vendor diff --git a/org.eclipse.egit.github.core.tests/build.properties b/org.eclipse.egit.github.core.tests/build.properties new file mode 100644 index 000000000..84f1c95cf --- /dev/null +++ b/org.eclipse.egit.github.core.tests/build.properties @@ -0,0 +1,6 @@ +source.. = src/,\ + resources/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/org.eclipse.egit.github.core.tests/plugin.properties b/org.eclipse.egit.github.core.tests/plugin.properties new file mode 100644 index 000000000..37bf93f4e --- /dev/null +++ b/org.eclipse.egit.github.core.tests/plugin.properties @@ -0,0 +1,2 @@ +Bundle-Name=EGit GitHub API Tests +Bundle-Vendor=Eclipse EGit \ No newline at end of file diff --git a/org.eclipse.egit.github.core.tests/pom.xml b/org.eclipse.egit.github.core.tests/pom.xml new file mode 100644 index 000000000..81c4d109e --- /dev/null +++ b/org.eclipse.egit.github.core.tests/pom.xml @@ -0,0 +1,48 @@ + + + + + 4.0.0 + + + org.eclipse.mylyn.github + github-parent + 5.5.0-SNAPSHOT + + + org.eclipse.egit.github.core.tests + eclipse-test-plugin + + Eclipse EGit GitHub API Test Plug-in + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + + + **/Test*.class + + false + false + org.eclipse.egit.github.core.tests + org.eclipse.egit.github.core.tests.AllHeadlessTests + + + + + diff --git a/org.eclipse.egit.github.core.tests/resources/org/eclipse/egit/github/core/tests/test_repo.json b/org.eclipse.egit.github.core.tests/resources/org/eclipse/egit/github/core/tests/test_repo.json new file mode 100644 index 000000000..545ddfeaf --- /dev/null +++ b/org.eclipse.egit.github.core.tests/resources/org/eclipse/egit/github/core/tests/test_repo.json @@ -0,0 +1,98 @@ +{ + "id": 1234567, + "name": "some-repo", + "full_name": "some-user/some-repo", + "owner": { + "login": "some-user", + "id": 123456, + "avatar_url": "", + "gravatar_id": "", + "url": "https://api.github.com/users/some-user", + "html_url": "https://github.com/some-user", + "followers_url": "https://api.github.com/users/some-user/followers", + "following_url": "https://api.github.com/users/some-user/following{/other_user}", + "gists_url": "https://api.github.com/users/some-user/gists{/gist_id}", + "starred_url": "https://api.github.com/users/some-user/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/some-user/subscriptions", + "organizations_url": "https://api.github.com/users/some-user/orgs", + "repos_url": "https://api.github.com/users/some-user/repos", + "events_url": "https://api.github.com/users/some-user/events{/privacy}", + "received_events_url": "https://api.github.com/users/some-user/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/some-user/some-repo", + "description": "Some fictitious test repo", + "fork": false, + "url": "https://api.github.com/repos/some-user/some-repo", + "forks_url": "https://api.github.com/repos/some-user/some-repo/forks", + "keys_url": "https://api.github.com/repos/some-user/some-repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/some-user/some-repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/some-user/some-repo/teams", + "hooks_url": "https://api.github.com/repos/some-user/some-repo/hooks", + "issue_events_url": "https://api.github.com/repos/some-user/some-repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/some-user/some-repo/events", + "assignees_url": "https://api.github.com/repos/some-user/some-repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/some-user/some-repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/some-user/some-repo/tags", + "blobs_url": "https://api.github.com/repos/some-user/some-repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/some-user/some-repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/some-user/some-repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/some-user/some-repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/some-user/some-repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/some-user/some-repo/languages", + "stargazers_url": "https://api.github.com/repos/some-user/some-repo/stargazers", + "contributors_url": "https://api.github.com/repos/some-user/some-repo/contributors", + "subscribers_url": "https://api.github.com/repos/some-user/some-repo/subscribers", + "subscription_url": "https://api.github.com/repos/some-user/some-repo/subscription", + "commits_url": "https://api.github.com/repos/some-user/some-repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/some-user/some-repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/some-user/some-repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/some-user/some-repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/some-user/some-repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/some-user/some-repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/some-user/some-repo/merges", + "archive_url": "https://api.github.com/repos/some-user/some-repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/some-user/some-repo/downloads", + "issues_url": "https://api.github.com/repos/some-user/some-repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/some-user/some-repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/some-user/some-repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/some-user/some-repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/some-user/some-repo/labels{/name}", + "releases_url": "https://api.github.com/repos/some-user/some-repo/releases{/id}", + "deployments_url": "https://api.github.com/repos/some-user/some-repo/deployments", + "created_at": "2018-05-08T08:00:00Z", + "updated_at": "2018-05-08T10:01:01Z", + "pushed_at": "2018-05-08T10:00:58Z", + "git_url": "git://github.com/some-user/some-repo.git", + "ssh_url": "git@github.com:some-user/some-repo.git", + "clone_url": "https://github.com/some-user/some-repo.git", + "svn_url": "https://github.com/some-user/some-repo", + "homepage": "", + "size": 677, + "stargazers_count": 21, + "watchers_count": 21, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 2, + "mirror_url": null, + "archived": false, + "open_issues_count": 3, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0" + }, + "forks": 2, + "open_issues": 3, + "watchers": 21, + "default_branch": "master", + "network_count": 2, + "subscribers_count": 9 +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java new file mode 100644 index 000000000..0df5e00eb --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AllHeadlessTests.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * David Green - initial contribution + * Christian Trutz - initial contribution + * Chris Aniszczyk - initial contribution + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +/** + * All headless unit tests of GitHub Java API + */ +@RunWith(Suite.class) +@SuiteClasses({ ApplicationTest.class, // + AuthorizationTest.class, // + BlobTest.class, // + CollaboratorServiceTest.class, // + CommentTest.class, // + CommitCommentPayloadTest.class, // + CommitCommentTest.class, // + CommitFileTest.class, // + CommitServiceTest.class, // + CommitStatsTest.class, // + CommitStatusTest.class, // + CommitTest.class, // + CommitUserTest.class, // + ContentsServiceTest.class, // + ContributorTest.class, // + CreatePayloadTest.class, // + DataServiceTest.class, // + DateFormatterTest.class, // + DateUtilTest.class, // + DeletePayloadTest.class, // + DeployKeyServiceTest.class, // + DownloadPayloadTest.class, // + DownloadResourceTest.class, // + DownloadServiceTest.class, // + DownloadTest.class, // + EncodingUtilsTest.class, // + EventFormatterTest.class, // + EventPayloadTest.class, // + EventRepositoryTest.class, // + EventServiceTest.class, // + EventTest.class, // + FieldErrorTest.class, // + FollowPayloadTest.class, // + ForkApplyPayloadTest.class, // + ForkPayloadTest.class, // + GistChangeStatusTest.class, // + GistFileTest.class, // + GistPayloadTest.class, // + GistRevisionTest.class, // + GistServiceTest.class, // + GistTest.class, // + GitHubClientTest.class, // + GollumPageTest.class, // + GollumPayloadTest.class, // + GsonUtilsTest.class, // + IdTest.class, // + IssueCommentPayloadTest.class, // + IssueEventTest.class, // + IssueServiceTest.class, // + IssueTest.class, // + IssuesPayloadTest.class, // + KeyTest.class, // + LabelComparatorTest.class, // + LabelServiceTest.class, // + LabelTest.class, // + LanguageTest.class, // + MarkdownServiceTest.class, // + MemberPayloadTest.class, // + MergeStatusTest.class, // + MilestoneComparatorTest.class, // + MilestoneServiceTest.class, // + MilestoneTest.class, // + OAuthServiceTest.class, // + OrganizationServiceTest.class, // + PagedRequestTest.class, // + PullRequestMarkerTest.class, // + PullRequestPayloadTest.class, // + PullRequestReviewCommentPayloadTest.class, // + PullRequestServiceTest.class, // + PullRequestTest.class, // + PushPayloadTest.class, // + ReferenceTest.class, // + RepositoryBranchTest.class, // + RepositoryCommitCompareTest.class, // + RepositoryCommitTest.class, // + RepositoryContentsTest.class, // + RepositoryHookResponseTest.class, // + RepositoryHookTest.class, // + RepositoryIdTest.class, // + RepositoryIssueTest.class, // + RepositoryServiceTest.class, // + RepositoryTagTest.class, // + RepositoryTest.class, // + RequestErrorTest.class, // + RequestExceptionTest.class, // + SearchIssueTest.class, // + SearchRepositoryTest.class, // + ShaResourceTest.class, // + StargazerServiceTest.class, // + TagTest.class, // + TeamAddPayloadTest.class, // + TeamServiceTest.class, // + TeamTest.class, // + TreeEntryTest.class, // + TreeTest.class, // + TypedResourceTest.class, // + UrlUtilsTest.class, // + UserPlanTest.class, // + UserServiceTest.class, // + UserTest.class, // + WatchPayloadTest.class, // +}) +public class AllHeadlessTests { + +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ApplicationTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ApplicationTest.java new file mode 100644 index 000000000..c6decffb6 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ApplicationTest.java @@ -0,0 +1,45 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Application; +import org.junit.Test; + +/** + * Unit tests of {@link Application} + */ +public class ApplicationTest { + + /** + * Test default state of application + */ + @Test + public void defaultState() { + Application app = new Application(); + assertNull(app.getName()); + assertNull(app.getUrl()); + } + + /** + * Test updating application fields + */ + @Test + public void updateFields() { + Application app = new Application(); + assertEquals("name", app.setName("name").getName()); + assertEquals("url", app.setUrl("url").getUrl()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AuthorizationTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AuthorizationTest.java new file mode 100644 index 000000000..446284e1d --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/AuthorizationTest.java @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.Collections; +import java.util.Date; + +import org.eclipse.egit.github.core.Application; +import org.eclipse.egit.github.core.Authorization; +import org.junit.Test; + +/** + * Unit tests of {@link Authorization} + */ +public class AuthorizationTest { + + /** + * Test default state of authorization + */ + @Test + public void defaultState() { + Authorization auth = new Authorization(); + assertNull(auth.getApp()); + assertNull(auth.getCreatedAt()); + assertEquals(0, auth.getId()); + assertNull(auth.getNote()); + assertNull(auth.getNoteUrl()); + assertNull(auth.getScopes()); + assertNull(auth.getToken()); + assertNull(auth.getUpdatedAt()); + assertNull(auth.getUrl()); + } + + /** + * Test updating application fields + */ + @Test + public void updateFields() { + Authorization auth = new Authorization(); + Application app = new Application(); + assertEquals(app, auth.setApp(app).getApp()); + assertEquals(new Date(2500), auth.setCreatedAt(new Date(2500)) + .getCreatedAt()); + assertEquals(123, auth.setId(123).getId()); + assertEquals("note", auth.setNote("note").getNote()); + assertEquals("noteUrl", auth.setNoteUrl("noteUrl").getNoteUrl()); + assertEquals(Collections.singletonList("repo"), + auth.setScopes(Collections.singletonList("repo")).getScopes()); + assertEquals("token", auth.setToken("token").getToken()); + assertEquals(new Date(8000), auth.setUpdatedAt(new Date(8000)) + .getUpdatedAt()); + assertEquals("url", auth.setUrl("url").getUrl()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/BlobTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/BlobTest.java new file mode 100644 index 000000000..f4eeaef17 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/BlobTest.java @@ -0,0 +1,46 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Blob; +import org.junit.Test; + +/** + * Unit tests of {@link Blob} class + */ +public class BlobTest { + + /** + * Test default state of blob + */ + @Test + public void defaultState() { + Blob blob = new Blob(); + assertNull(blob.getContent()); + assertNull(blob.getEncoding()); + } + + /** + * Test updating blob fields + */ + @Test + public void updateFields() { + Blob blob = new Blob(); + assertEquals("content123", blob.setContent("content123").getContent()); + assertEquals(Blob.ENCODING_UTF8, blob.setEncoding(Blob.ENCODING_UTF8) + .getEncoding()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CollaboratorServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CollaboratorServiceTest.java new file mode 100644 index 000000000..2721a88b1 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CollaboratorServiceTest.java @@ -0,0 +1,183 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; + +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.service.CollaboratorService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link CollaboratorService} + */ +@RunWith(MockitoJUnitRunner.class) +public class CollaboratorServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private CollaboratorService service; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(client).get(any(GitHubRequest.class)); + service = new CollaboratorService(client); + } + + /** + * Create service using default constructor + */ + @Test + public void constructor() { + assertNotNull(new CollaboratorService().getClient()); + } + + /** + * Get all collaborators for repository + * + * @throws IOException + */ + @Test + public void getCollaborators() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.getCollaborators(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/u/p/collaborators")); + verify(client).get(request); + } + + /** + * Check collaborator with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void isCollaboratorNullUser() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.isCollaborator(repo, null); + } + + /** + * Check collaborator with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void isCollaboratorEmptyUser() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.isCollaborator(repo, ""); + } + + /** + * Check collaborator + * + * @throws IOException + */ + @Test + public void isCollaborator() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.isCollaborator(repo, "collab"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/u/p/collaborators/collab"); + verify(client).get(request); + } + + /** + * Add collaborator + * + * @throws IOException + */ + @Test + public void addCollaborator() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.addCollaborator(repo, "collab"); + verify(client).put("/repos/u/p/collaborators/collab"); + } + + /** + * Add collaborator with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void addCollaboratorNullUser() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.addCollaborator(repo, null); + } + + /** + * Add collaborator with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void addCollaboratorEmptyUser() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.addCollaborator(repo, ""); + } + + /** + * Remove collaborator + * + * @throws IOException + */ + @Test + public void delete() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.removeCollaborator(repo, "collab"); + verify(client).delete("/repos/u/p/collaborators/collab"); + } + + /** + * Remove collaborator with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void removeCollaboratorNullUser() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.removeCollaborator(repo, null); + } + + /** + * Remove collaborator with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void removeCollaboratorEmptyUser() throws IOException { + RepositoryId repo = new RepositoryId("u", "p"); + service.removeCollaborator(repo, ""); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java new file mode 100644 index 000000000..5e1a81cec --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommentTest.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.eclipse.egit.github.core.Comment; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link Comment} + */ +public class CommentTest { + + /** + * Test default state of comment + */ + @Test + public void defaultState() { + Comment comment = new Comment(); + assertNull(comment.getBody()); + assertNull(comment.getBodyHtml()); + assertNull(comment.getBodyText()); + assertNull(comment.getCreatedAt()); + assertEquals(0, comment.getId()); + assertNull(comment.getUpdatedAt()); + assertNull(comment.getUrl()); + assertNull(comment.getUser()); + } + + /** + * Test updating comment fields + */ + @Test + public void updateFields() { + Comment comment = new Comment(); + assertEquals("body", comment.setBody("body").getBody()); + assertEquals("", comment.setBodyHtml("").getBodyHtml()); + assertEquals("text", comment.setBodyText("text").getBodyText()); + assertEquals(new Date(1234), comment.setCreatedAt(new Date(1234)) + .getCreatedAt()); + assertEquals(100, comment.setId(100).getId()); + assertEquals(new Date(2345), comment.setUpdatedAt(new Date(2345)) + .getUpdatedAt()); + assertEquals("http", comment.setUrl("http").getUrl()); + User user = new User().setLogin("auser"); + assertEquals(user, comment.setUser(user).getUser()); + } + + /** + * Test non-mutable created at date + */ + @Test + public void getCreatedAtReferenceMutableObject() { + Comment comment = new Comment(); + comment.setCreatedAt(new Date(12345)); + comment.getCreatedAt().setTime(0); + assertTrue(comment.getCreatedAt().getTime() != 0); + } + + /** + * Test non-mutable updated at date + */ + @Test + public void getUpdatedAtReferenceMutableObject() { + Comment comment = new Comment(); + comment.setUpdatedAt(new Date(54321)); + comment.getUpdatedAt().setTime(0); + assertTrue(comment.getUpdatedAt().getTime() != 0); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitCommentPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitCommentPayloadTest.java new file mode 100644 index 000000000..71ee6b71b --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitCommentPayloadTest.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.CommitComment; +import org.eclipse.egit.github.core.event.CommitCommentPayload; +import org.junit.Test; + +/** + * Unit tests of {@link CommitCommentPayload} + */ +public class CommitCommentPayloadTest { + + /** + * Test default state of CommitCommentPayload + */ + @Test + public void defaultState() { + CommitCommentPayload payload = new CommitCommentPayload(); + assertNull(payload.getComment()); + } + + /** + * Test updating CommitCommentPayload fields + */ + @Test + public void updateFields() { + CommitCommentPayload payload = new CommitCommentPayload(); + CommitComment comment = new CommitComment(); + comment.setBody("comment"); + assertEquals(comment, payload.setComment(comment).getComment()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitCommentTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitCommentTest.java new file mode 100644 index 000000000..a7110de75 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitCommentTest.java @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.Date; + +import org.eclipse.egit.github.core.CommitComment; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link CommitComment} + */ +public class CommitCommentTest { + + /** + * Test default state of commit comment + */ + @Test + public void defaultState() { + CommitComment comment = new CommitComment(); + assertNull(comment.getBody()); + assertNull(comment.getCommitId()); + assertNull(comment.getCreatedAt()); + assertEquals(0, comment.getId()); + assertEquals(0, comment.getLine()); + assertNull(comment.getPath()); + assertEquals(0, comment.getPosition()); + assertNull(comment.getUpdatedAt()); + assertNull(comment.getUrl()); + assertNull(comment.getUser()); + } + + /** + * Test updating commit comment fields + */ + @Test + public void updateFields() { + CommitComment comment = new CommitComment(); + assertEquals("a body", comment.setBody("a body").getBody()); + assertEquals("123abc", comment.setCommitId("123abc").getCommitId()); + assertEquals(new Date(8000), comment.setCreatedAt(new Date(8000)) + .getCreatedAt()); + assertEquals(20, comment.setId(20).getId()); + assertEquals(12, comment.setLine(12).getLine()); + assertEquals("/a/path", comment.setPath("/a/path").getPath()); + assertEquals(4, comment.setPosition(4).getPosition()); + assertEquals(new Date(10000), comment.setUpdatedAt(new Date(10000)) + .getUpdatedAt()); + assertEquals("http://url", comment.setUrl("http://url").getUrl()); + User user = new User().setLogin("theuser"); + assertEquals(user, comment.setUser(user).getUser()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitFileTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitFileTest.java new file mode 100644 index 000000000..d42afeb64 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitFileTest.java @@ -0,0 +1,59 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.CommitFile; +import org.junit.Test; + +/** + * Unit tests of {@link CommitFile} + */ +public class CommitFileTest { + + /** + * Test default state of commit file + */ + @Test + public void defaultState() { + CommitFile file = new CommitFile(); + assertEquals(0, file.getAdditions()); + assertEquals(0, file.getChanges()); + assertEquals(0, file.getDeletions()); + assertNull(file.getBlobUrl()); + assertNull(file.getFilename()); + assertNull(file.getPatch()); + assertNull(file.getRawUrl()); + assertNull(file.getSha()); + assertNull(file.getStatus()); + } + + /** + * Test updating commit file fields + */ + @Test + public void updateFields() { + CommitFile file = new CommitFile(); + assertEquals(123, file.setAdditions(123).getAdditions()); + assertEquals(456, file.setChanges(456).getChanges()); + assertEquals(789, file.setDeletions(789).getDeletions()); + assertEquals("blob url", file.setBlobUrl("blob url").getBlobUrl()); + assertEquals("file.txt", file.setFilename("file.txt").getFilename()); + assertEquals("file.patch", file.setPatch("file.patch").getPatch()); + assertEquals("raw url", file.setRawUrl("raw url").getRawUrl()); + assertEquals("aaaaa", file.setSha("aaaaa").getSha()); + assertEquals("add", file.setStatus("add").getStatus()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java new file mode 100644 index 000000000..4b0e0ed6b --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java @@ -0,0 +1,664 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.egit.github.core.CommitComment; +import org.eclipse.egit.github.core.CommitStatus; +import org.eclipse.egit.github.core.RepositoryCommit; +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.client.PageIterator; +import org.eclipse.egit.github.core.service.CommitService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link CommitService} + */ +@RunWith(MockitoJUnitRunner.class) +public class CommitServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private CommitService service; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(client).get(any(GitHubRequest.class)); + service = new CommitService(client); + } + + /** + * Create service using default constructor + */ + @Test + public void constructor() { + assertNotNull(new CommitService().getClient()); + } + + /** + * Get commits + * + * @throws IOException + */ + @Test + public void getCommits() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommits(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/commits")); + verify(client).get(request); + } + + /** + * Page commits + */ + @Test + public void pageCommits() { + RepositoryId repo = new RepositoryId("o", "n"); + PageIterator iterator = service.pageCommits(repo); + assertNotNull(iterator); + assertEquals(Utils.page("/repos/o/n/commits"), iterator.getRequest() + .generateUri()); + assertTrue(iterator.hasNext()); + } + + /** + * Get commit with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitNullSha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommit(repo, null); + } + + /** + * Get commit with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitEmptySha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommit(repo, ""); + } + + /** + * Get commit + * + * @throws IOException + */ + @Test + public void getCommit() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommit(repo, "abc"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/commits/abc"); + verify(client).get(request); + } + + /** + * Get commit diff with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitDiffNullSha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommitDiff(repo, null); + } + + /** + * Get commit diff with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitDiffEmptySha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommitDiff(repo, ""); + } + + /** + * Get commit diff + * + * @throws IOException + */ + @Test + public void getCommitDiff() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommitDiff(repo, "abc"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/commits/abc"); + request.setResponseContentType("application/vnd.github.v3.diff"); + verify(client).getStream(request); + } + + /** + * Get commit patch with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitPatchNullSha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommitPatch(repo, null); + } + + /** + * Get commit patch with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitPatchEmptySha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommitPatch(repo, ""); + } + + /** + * Get commit patch + * + * @throws IOException + */ + @Test + public void getCommitPatch() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getCommitPatch(repo, "abc"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/commits/abc"); + request.setResponseContentType("application/vnd.github.v3.patch"); + verify(client).getStream(request); + } + + /** + * Get comments with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsNullSha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getComments(repo, null); + } + + /** + * Get comments with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsEmptySha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getComments(repo, ""); + } + + /** + * Get commit comments + * + * @throws IOException + */ + @Test + public void getCommitComments() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getComments(repo, "abc"); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/commits/abc/comments")); + verify(client).get(request); + } + + /** + * Get all commit comments + * + * @throws IOException + */ + @Test + public void getAllComments() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getComments(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/comments")); + verify(client).get(request); + } + + /** + * Get comment comment + * + * @throws IOException + */ + @Test + public void getComment() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getComment(repo, 33); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/comments/33"); + verify(client).get(request); + } + + /** + * Add comment with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void addCommentNullSha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitComment comment = new CommitComment(); + service.addComment(repo, null, comment); + } + + /** + * Add comment with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void addCommentEmptySha() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitComment comment = new CommitComment(); + service.addComment(repo, "", comment); + } + + /** + * Add commit comment + * + * @throws IOException + */ + @Test + public void addComment() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitComment comment = new CommitComment(); + service.addComment(repo, "abcd", comment); + verify(client).post("/repos/o/n/commits/abcd/comments", comment, + CommitComment.class); + } + + /** + * Edit with null comment + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editCommentNullComment() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.editComment(repo, null); + } + + /** + * Edit commit comment + * + * @throws IOException + */ + @Test + public void editComment() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitComment comment = new CommitComment(); + comment.setId(56); + service.editComment(repo, comment); + verify(client).post("/repos/o/n/comments/56", comment, + CommitComment.class); + } + + /** + * Delete commit comment + * + * @throws IOException + */ + @Test + public void deleteComment() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.deleteComment(repo, 75); + verify(client).delete("/repos/o/n/comments/75"); + } + + /** + * Compare commits with null base + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareNullBase() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compare(repo, null, "HEAD"); + } + + /** + * Compare commits with empty base + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareEmptyBase() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compare(repo, "", "HEAD"); + } + + /** + * Compare commits with null head + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareNullHead() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compare(repo, "HEAD~1", null); + } + + /** + * Compare commits empty head + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareEmptyHead() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compare(repo, "HEAD~1", ""); + } + + /** + * Compare commits + * + * @throws IOException + */ + @Test + public void compare() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compare(repo, "v1", "HEAD"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/compare/v1...HEAD"); + verify(client).get(request); + } + + /** + * Generate diff for commit comparison with null base + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareDiffNullBase() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compareDiff(repo, null, "HEAD"); + } + + /** + * Generate diff for commit comparison with empty base + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareDiffEmptyBase() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compareDiff(repo, "", "HEAD"); + } + + /** + * Generate diff for commit comparison with null head + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareDiffNullHead() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compareDiff(repo, "HEAD~1", null); + } + + /** + * Generate diff for commit comparison with empty head + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void compareDiffEmptyHead() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compareDiff(repo, "HEAD~1", ""); + } + + /** + * Generate diff for commit comparison + * + * @throws IOException + */ + @Test + public void compareDiff() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.compareDiff(repo, "v1", "HEAD"); + GitHubRequest request = new GitHubRequest(); + request.setResponseContentType("application/vnd.github.v3.diff"); + request.setUri("/repos/o/n/compare/v1...HEAD"); + verify(client).getStream(request); + } + + /** + * Generate patch for commit comparison with null base + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void comparePatchNullBase() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.comparePatch(repo, null, "HEAD"); + } + + /** + * Generate patch for commit comparison with empty base + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void comparePatchEmptyBase() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.comparePatch(repo, "", "HEAD"); + } + + /** + * Generate patch for commit comparison with null head + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void comparePatchNullHead() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.comparePatch(repo, "HEAD~1", null); + } + + /** + * Generate patch for commit comparison with empty head + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void comparePatchEmptyHead() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.comparePatch(repo, "HEAD~1", ""); + } + + /** + * Generate patch for commit comparison + * + * @throws IOException + */ + @Test + public void comparePatch() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.comparePatch(repo, "v1", "HEAD"); + GitHubRequest request = new GitHubRequest(); + request.setResponseContentType("application/vnd.github.v3.patch"); + request.setUri("/repos/o/n/compare/v1...HEAD"); + verify(client).getStream(request); + } + + /** + * Get statuses + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getStatusesNullRepository() throws IOException { + service.getStatuses(null, "123"); + } + + /** + * Get statuses + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getStatusesNullSha() throws IOException { + service.getStatuses(new RepositoryId("o", "n"), null); + } + + /** + * Get statuses + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getStatusesEmptySha() throws IOException { + service.getStatuses(new RepositoryId("o", "n"), ""); + } + + /** + * Get statuses + * + * @throws IOException + */ + @Test + public void getStatuses() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + service.getStatuses(repo, "123"); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/statuses/123")); + verify(client).get(request); + } + + /** + * Create status + * + * @throws IOException + */ + @Test + public void createStatus() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitStatus status = new CommitStatus(); + status.setDescription("description"); + status.setTargetUrl("http://target/url"); + status.setState(CommitStatus.STATE_SUCCESS); + status.setContext("context"); + service.createStatus(repo, "123", status); + Map params = new HashMap(); + params.put("description", status.getDescription()); + params.put("target_url", status.getTargetUrl()); + params.put("state", status.getState()); + params.put("context", status.getContext()); + verify(client).post("/repos/o/n/statuses/123", params, + CommitStatus.class); + } + + /** + * Create status + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createStatusNullRepository() throws IOException { + CommitStatus status = new CommitStatus(); + status.setDescription("description"); + status.setTargetUrl("http://target/url"); + status.setState(CommitStatus.STATE_SUCCESS); + status.setContext("context"); + service.createStatus(null, "123", status); + } + + /** + * Create status + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createStatusNullSha() throws IOException { + CommitStatus status = new CommitStatus(); + status.setDescription("description"); + status.setTargetUrl("http://target/url"); + status.setState(CommitStatus.STATE_SUCCESS); + status.setContext("context"); + service.createStatus(new RepositoryId("o", "n"), null, status); + } + + /** + * Create status + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createStatusEmptySha() throws IOException { + CommitStatus status = new CommitStatus(); + status.setDescription("description"); + status.setTargetUrl("http://target/url"); + status.setState(CommitStatus.STATE_SUCCESS); + status.setContext("context"); + service.createStatus(new RepositoryId("o", "n"), "", status); + } + + /** + * Create status + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createStatusNullStatus() throws IOException { + service.createStatus(new RepositoryId("o", "n"), "123", null); + } + + /** + * Create status + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createStatusInvalidState() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitStatus status = new CommitStatus(); + status.setState("non-existing-state"); + status.setDescription("description"); + status.setTargetUrl("http://target/url"); + status.setContext("context"); + service.createStatus(repo, "123", status); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatsTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatsTest.java new file mode 100644 index 000000000..d4011f7eb --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatsTest.java @@ -0,0 +1,46 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.egit.github.core.CommitStats; +import org.junit.Test; + +/** + * + */ +public class CommitStatsTest { + + /** + * Test default state of commit stats + */ + @Test + public void defaultState() { + CommitStats stats = new CommitStats(); + assertEquals(0, stats.getAdditions()); + assertEquals(0, stats.getDeletions()); + assertEquals(0, stats.getTotal()); + } + + /** + * Test updating commit stats fields + */ + @Test + public void updateFields() { + CommitStats stats = new CommitStats(); + assertEquals(10, stats.setAdditions(10).getAdditions()); + assertEquals(36, stats.setDeletions(36).getDeletions()); + assertEquals(123, stats.setTotal(123).getTotal()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java new file mode 100644 index 000000000..607e353bb --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java @@ -0,0 +1,68 @@ +/****************************************************************************** + * Copyright (c) 2012, 2015 GitHub Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.Date; + +import org.eclipse.egit.github.core.CommitStatus; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link CommitStatus} + */ +public class CommitStatusTest { + + /** + * Test default state of commit status + */ + @Test + public void defaultState() { + CommitStatus status = new CommitStatus(); + assertNull(status.getCreatedAt()); + assertNull(status.getCreator()); + assertNull(status.getContext()); + assertNull(status.getDescription()); + assertEquals(0, status.getId()); + assertNull(status.getState()); + assertNull(status.getTargetUrl()); + assertNull(status.getUpdatedAt()); + assertNull(status.getUrl()); + assertNull(status.getContext()); + } + + /** + * Test updating commit status fields + */ + @Test + public void updateFields() { + CommitStatus status = new CommitStatus(); + assertEquals(new Date(1234), status.setCreatedAt(new Date(1234)) + .getCreatedAt()); + User creator = new User().setId(1); + assertEquals(creator, status.setCreator(creator).getCreator()); + assertEquals("con/text", status.setContext("con/text").getContext()); + assertEquals("desc", status.setDescription("desc").getDescription()); + assertEquals(40, status.setId(40).getId()); + assertEquals("success", status.setState("success").getState()); + assertEquals("targetUrl", status.setTargetUrl("targetUrl") + .getTargetUrl()); + assertEquals(new Date(5678), status.setUpdatedAt(new Date(5678)) + .getUpdatedAt()); + assertEquals("url", status.setUrl("url").getUrl()); + assertEquals("context", status.setContext("context").getContext()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitTest.java new file mode 100644 index 000000000..c2e0823ce --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitTest.java @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; + +import org.eclipse.egit.github.core.Commit; +import org.eclipse.egit.github.core.CommitUser; +import org.eclipse.egit.github.core.Tree; +import org.junit.Test; + +/** + * Unit tests of {@link Commit} + */ +public class CommitTest { + + /** + * Test default state of commit + */ + @Test + public void defaultState() { + Commit commit = new Commit(); + assertNull(commit.getAuthor()); + assertNull(commit.getCommitter()); + assertNull(commit.getMessage()); + assertNull(commit.getParents()); + assertNull(commit.getSha()); + assertNull(commit.getTree()); + assertNull(commit.getUrl()); + assertEquals(0, commit.getCommentCount()); + } + + /** + * Test updating commit fields + */ + @Test + public void updateFields() { + Commit commit = new Commit(); + CommitUser author = new CommitUser().setName("Art Thor"); + assertEquals(author, commit.setAuthor(author).getAuthor()); + CommitUser committer = new CommitUser().setName("Comb Mitter"); + assertEquals(committer, commit.setCommitter(committer).getCommitter()); + assertEquals("commit message", commit.setMessage("commit message") + .getMessage()); + assertEquals(new ArrayList(), + commit.setParents(new ArrayList()).getParents()); + assertEquals("abcdef", commit.setSha("abcdef").getSha()); + Tree tree = new Tree(); + tree.setSha("12345"); + assertEquals(tree, commit.setTree(tree).getTree()); + assertEquals("url", commit.setUrl("url").getUrl()); + assertEquals(32, commit.setCommentCount(32).getCommentCount()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitUserTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitUserTest.java new file mode 100644 index 000000000..5ea5b078e --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitUserTest.java @@ -0,0 +1,49 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.Date; + +import org.eclipse.egit.github.core.CommitUser; +import org.junit.Test; + +/** + * Unit tests of {@link CommitUser} + */ +public class CommitUserTest { + + /** + * Test default state of commit user + */ + @Test + public void defaultState() { + CommitUser user = new CommitUser(); + assertNull(user.getDate()); + assertNull(user.getEmail()); + assertNull(user.getName()); + } + + /** + * Test updating commit user fields + */ + @Test + public void updateFields() { + CommitUser user = new CommitUser(); + assertEquals(new Date(123456), user.setDate(new Date(123456)).getDate()); + assertEquals("a@b.com", user.setEmail("a@b.com").getEmail()); + assertEquals("a user", user.setName("a user").getName()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContentsServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContentsServiceTest.java new file mode 100644 index 000000000..2ce4f00c1 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContentsServiceTest.java @@ -0,0 +1,118 @@ +/****************************************************************************** + * Copyright (c) 2012 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; + +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.service.ContentsService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link ContentsService} + */ +@RunWith(MockitoJUnitRunner.class) +public class ContentsServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private ContentsService service; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(client).get(any(GitHubRequest.class)); + service = new ContentsService(client); + } + + /** + * Get readme for null repository + * + * @throws Exception + */ + @Test(expected = IllegalArgumentException.class) + public void getReadmeNullRepository() throws Exception { + service.getReadme(null); + } + + /** + * Get readme for repository + * + * @throws Exception + */ + @Test + public void getReadme() throws Exception { + RepositoryId repo = new RepositoryId("o", "n"); + service.getReadme(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/readme"); + verify(client).get(request); + } + + /** + * Get contents for null repository + * + * @throws Exception + */ + @Test(expected = IllegalArgumentException.class) + public void getContentsNullRepository() throws Exception { + service.getContents(null); + } + + /** + * Get contents at root in repository + * + * @throws Exception + */ + @Test + public void getRootContents() throws Exception { + RepositoryId repo = new RepositoryId("o", "n"); + service.getContents(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/contents"); + verify(client).get(request); + } + + /** + * Get contents at path in repository + * + * @throws Exception + */ + @Test + public void getContents() throws Exception { + RepositoryId repo = new RepositoryId("o", "n"); + service.getContents(repo, "a/b"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/contents/a/b"); + verify(client).get(request); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContributorTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContributorTest.java new file mode 100644 index 000000000..b13de016f --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ContributorTest.java @@ -0,0 +1,57 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Contributor; +import org.junit.Test; + +/** + * Unit tests of {@link Contributor} + */ +public class ContributorTest { + + /** + * Test default state of contributor + */ + @Test + public void defaultState() { + Contributor contributor = new Contributor(); + assertNull(contributor.getAvatarUrl()); + assertEquals(0, contributor.getContributions()); + assertEquals(0, contributor.getId()); + assertNull(contributor.getLogin()); + assertNull(contributor.getName()); + assertNull(contributor.getType()); + assertNull(contributor.getUrl()); + } + + /** + * Test updating contributor fields + */ + @Test + public void updateFields() { + Contributor contributor = new Contributor(); + assertEquals("aUrl", contributor.setAvatarUrl("aUrl").getAvatarUrl()); + assertEquals(10, contributor.setContributions(10).getContributions()); + assertEquals(4321, contributor.setId(4321).getId()); + assertEquals("user", contributor.setLogin("user").getLogin()); + assertEquals("U ser", contributor.setName("U ser").getName()); + assertEquals(Contributor.TYPE_ANONYMOUS, + contributor.setType(Contributor.TYPE_ANONYMOUS).getType()); + assertEquals("url", contributor.setUrl("url").getUrl()); + } + +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CreatePayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CreatePayloadTest.java new file mode 100644 index 000000000..47b571de7 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CreatePayloadTest.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.event.CreatePayload; +import org.junit.Test; + +/** + * Unit tests of {@link CreatePayload} + */ +public class CreatePayloadTest { + + /** + * Test default state of CreatePayload + */ + @Test + public void defaultState() { + CreatePayload payload = new CreatePayload(); + assertNull(payload.getRefType()); + assertNull(payload.getRef()); + assertNull(payload.getMasterBranch()); + assertNull(payload.getDescription()); + } + + /** + * Test updating CreatePayload fields + */ + @Test + public void updateFields() { + CreatePayload payload = new CreatePayload(); + assertEquals("branch", payload.setRefType("branch").getRefType()); + assertEquals("ref", payload.setRef("ref").getRef()); + assertEquals("master", payload.setMasterBranch("master").getMasterBranch()); + assertEquals("description", + payload.setDescription("description").getDescription()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DataServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DataServiceTest.java new file mode 100644 index 000000000..d2f5ccabc --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DataServiceTest.java @@ -0,0 +1,485 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; + +import org.eclipse.egit.github.core.Blob; +import org.eclipse.egit.github.core.Commit; +import org.eclipse.egit.github.core.Reference; +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.ShaResource; +import org.eclipse.egit.github.core.Tag; +import org.eclipse.egit.github.core.Tree; +import org.eclipse.egit.github.core.TypedResource; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.service.DataService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link DataService} + */ +@RunWith(MockitoJUnitRunner.class) +public class DataServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private DataService service; + + private RepositoryId repo; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(client).get(any(GitHubRequest.class)); + service = new DataService(client); + repo = new RepositoryId("o", "n"); + } + + /** + * Create service using default constructor + */ + @Test + public void constructor() { + assertNotNull(new DataService().getClient()); + } + + /** + * Get blob with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getBlobNullSha() throws IOException { + service.getBlob(repo, null); + } + + /** + * Get blob with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getBlobEmptySha() throws IOException { + service.getBlob(repo, ""); + } + + /** + * Get blob + * + * @throws IOException + */ + @Test + public void getBlob() throws IOException { + service.getBlob(repo, "aaa"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/git/blobs/aaa"); + verify(client).get(request); + } + + /** + * Create blob with null blob + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createBlobNullBlob() throws IOException { + service.createBlob(repo, null); + } + + /** + * Create blob + * + * @throws IOException + */ + @Test + public void createBlob() throws IOException { + Blob blob = new Blob().setContent("a"); + service.createBlob(repo, blob); + verify(client).post("/repos/o/n/git/blobs", blob, ShaResource.class); + } + + /** + * Get tree with null sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getTreeNullSha() throws IOException { + service.getTree(repo, null); + } + + /** + * Get tree with empty sha + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getTreeEmptySha() throws IOException { + service.getTree(repo, ""); + } + + /** + * Get tree + * + * @throws IOException + */ + @Test + public void getTree() throws IOException { + service.getTree(repo, "abc"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/git/trees/abc"); + verify(client).get(request); + } + + /** + * Create tree + * + * @throws IOException + */ + @Test + public void createTree() throws IOException { + service.createTree(repo, null); + verify(client).post("/repos/o/n/git/trees", + new HashMap(), Tree.class); + } + + /** + * Get reference with null name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getReferenceNullName() throws IOException { + service.getReference(repo, null); + } + + /** + * Get reference for empty name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getReferenceEmptyName() throws IOException { + service.getReference(repo, ""); + } + + /** + * Get reference + * + * @throws IOException + */ + @Test + public void getReference() throws IOException { + service.getReference(repo, "refs/heads/master"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/git/refs/heads/master"); + verify(client).get(request); + } + + /** + * Get references + * + * @throws IOException + */ + @Test + public void getReferences() throws IOException { + service.getReferences(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/git/refs")); + verify(client).get(request); + } + + /** + * Create reference with null reference + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createReferenceNullReference() throws IOException { + service.createReference(repo, null); + } + + /** + * Create reference with null object + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createReferenceNullObject() throws IOException { + service.createReference(repo, new Reference()); + } + + /** + * Create reference + * + * @throws IOException + */ + @Test + public void createReference() throws IOException { + Reference ref = new Reference(); + ref.setRef("refs/heads/master"); + TypedResource object = new TypedResource(); + object.setSha("abcdef"); + ref.setObject(object); + service.createReference(repo, ref); + verify(client).post(eq("/repos/o/n/git/refs"), any(), + eq(Reference.class)); + } + + /** + * Edit reference with null reference + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editReferenceNullReference() throws IOException { + service.editReference(repo, null); + } + + /** + * Edit reference with null object + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editReferenceNullObject() throws IOException { + service.editReference(repo, new Reference().setRef("a")); + } + + /** + * Edit reference with null name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editReferenceNullName() throws IOException { + service.editReference(repo, + new Reference().setObject(new TypedResource())); + } + + /** + * Edit reference with empty name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editReferenceEmptyName() throws IOException { + service.editReference(repo, + new Reference().setObject(new TypedResource()).setRef("")); + } + + /** + * Edit reference + * + * @throws IOException + */ + @Test + public void editReference() throws IOException { + Reference ref = new Reference(); + ref.setRef("refs/heads/master"); + TypedResource object = new TypedResource(); + object.setSha("00aa"); + ref.setObject(object); + service.editReference(repo, ref); + verify(client).post(eq("/repos/o/n/git/refs/heads/master"), any(), + eq(Reference.class)); + } + + /** + * Get commit with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitNullId() throws IOException { + service.getCommit(repo, null); + } + + /** + * Get commit with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommitEmptyId() throws IOException { + service.getCommit(repo, ""); + } + + /** + * Get commit + * + * @throws IOException + */ + @Test + public void getCommit() throws IOException { + service.getCommit(repo, "ccc"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/git/commits/ccc"); + verify(client).get(request); + } + + /** + * Create commit with null commit + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommitNullCommit() throws IOException { + service.createCommit(repo, null); + } + + /** + * Create commit + * + * @throws IOException + */ + @Test + public void createCommit() throws IOException { + Commit commit = new Commit(); + commit.setParents(Collections.singletonList(new Commit().setSha("abcd"))); + commit.setTree(new Tree().setSha("aaa")); + service.createCommit(repo, commit); + verify(client).post(eq("/repos/o/n/git/commits"), any(), + eq(Commit.class)); + } + + /** + * Get tag with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getTagNullId() throws IOException { + service.getTag(repo, null); + } + + /** + * Get tag with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getTagEmptyId() throws IOException { + service.getTag(repo, ""); + } + + /** + * Get tag + * + * @throws IOException + */ + @Test + public void getTag() throws IOException { + service.getTag(repo, "abcdef"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/git/tags/abcdef"); + verify(client).get(request); + } + + /** + * List tags + * + * @throws IOException + */ + @Test + public void listTags() throws IOException { + service.listTags(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/git/refs/tags")); + verify(client).get(request); + } + + /** + * Create tag with null tag + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createTagNullTag() throws IOException { + service.createTag(repo, null); + } + + /** + * Create tag + * + * @throws IOException + */ + @Test + public void createTag() throws IOException { + Tag tag = new Tag(); + tag.setObject(new TypedResource()); + service.createTag(repo, tag); + verify(client).post(eq("/repos/o/n/git/tags"), any(), eq(Tag.class)); + } + + /** + * Delete reference + * + * @throws IOException + */ + @Test + public void deleteReference() throws IOException { + Reference ref = new Reference(); + ref.setRef("refs/heads/master"); + service.deleteReference(repo, ref); + verify(client).delete(eq("/repos/o/n/git/refs/heads/master")); + } + + /** + * Delete branch + * + * @throws IOException + */ + @Test + public void deleteBranch() throws IOException { + String branch = "branch"; + service.deleteBranch(repo, branch); + verify(client).delete(eq("/repos/o/n/git/refs/heads/branch")); + } + + /** + * Delete tag + * + * @throws IOException + */ + @Test + public void deleteTag() throws IOException { + Tag tag = new Tag(); + tag.setTag("tag"); + service.deleteTag(repo, tag); + verify(client).delete(eq("/repos/o/n/git/refs/tags/tag")); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DateFormatterTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DateFormatterTest.java new file mode 100644 index 000000000..f47123927 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DateFormatterTest.java @@ -0,0 +1,57 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; + +import java.util.Date; + +import org.eclipse.egit.github.core.client.DateFormatter; +import org.junit.Test; + +/** + * Unit tests of {@link DateFormatter} + */ +public class DateFormatterTest { + + /** + * Verify serialized date returns value deserilized + */ + @Test + public void serializeDeserialize() { + DateFormatter formatter = new DateFormatter(); + Date date = new Date(10000); + JsonElement element = formatter.serialize(date, null, null); + assertNotNull(element); + String value = element.getAsString(); + assertNotNull(value); + assertTrue(value.length() > 0); + Date out = formatter.deserialize(element, null, null); + assertNotNull(out); + assertEquals(date.getTime(), out.getTime()); + } + + /** + * Deserialize empty string + */ + @Test(expected = JsonParseException.class) + public void emptyInput() { + new DateFormatter().deserialize(new JsonPrimitive(""), null, null); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DateUtilTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DateUtilTest.java new file mode 100644 index 000000000..1a94b979b --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DateUtilTest.java @@ -0,0 +1,50 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; + +import java.util.Date; + +import org.eclipse.egit.github.core.util.DateUtils; +import org.junit.Test; + +/** + * Unit tests of {@link DateUtils} + */ +public class DateUtilTest { + + /** + * Test default constructor through anonymous sub-class + */ + @Test + public void constructor() { + assertNotNull(new DateUtils() { + }); + } + + /** + * Test cloning date + */ + @Test + public void cloneDate() { + assertNull(DateUtils.clone(null)); + assertEquals(new Date(1000), DateUtils.clone(new Date(1000))); + Date date = new Date(25000); + assertNotSame(date, DateUtils.clone(date)); + } + +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DeletePayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DeletePayloadTest.java new file mode 100644 index 000000000..26d3bd489 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DeletePayloadTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.event.DeletePayload; +import org.junit.Test; + +/** + * Unit tests of {@link DeletePayload} + */ +public class DeletePayloadTest { + + /** + * Test default state of DeletePayload + */ + @Test + public void defaultState() { + DeletePayload payload = new DeletePayload(); + assertNull(payload.getRefType()); + assertNull(payload.getRef()); + } + + /** + * Test updating DeletePayload fields + */ + @Test + public void updateFields() { + DeletePayload payload = new DeletePayload(); + assertEquals("branch", payload.setRefType("branch").getRefType()); + assertEquals("ref", payload.setRef("ref").getRef()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DeployKeyServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DeployKeyServiceTest.java new file mode 100644 index 000000000..66b53405a --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DeployKeyServiceTest.java @@ -0,0 +1,140 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; + +import org.eclipse.egit.github.core.Key; +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.service.DeployKeyService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link DeployKeyService} + */ +@RunWith(MockitoJUnitRunner.class) +public class DeployKeyServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private DeployKeyService service; + + private RepositoryId repo; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(client).get(any(GitHubRequest.class)); + service = new DeployKeyService(client); + repo = new RepositoryId("o", "n"); + } + + /** + * Create service using default constructor + */ + @Test + public void constructor() { + assertNotNull(new DeployKeyService().getClient()); + } + + /** + * Get keys + * + * @throws IOException + */ + @Test + public void getKeys() throws IOException { + service.getKeys(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/keys")); + verify(client).get(request); + } + + /** + * Get key + * + * @throws IOException + */ + @Test + public void getKey() throws IOException { + service.getKey(repo, 40); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/keys/40"); + verify(client).get(request); + } + + /** + * Create key + * + * @throws IOException + */ + @Test + public void createKey() throws IOException { + Key key = new Key(); + service.createKey(repo, key); + verify(client).post("/repos/o/n/keys", key, Key.class); + } + + /** + * Edit key with null key + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editKeyNullKey() throws IOException { + service.editKey(repo, null); + } + + /** + * Edit key + * + * @throws IOException + */ + @Test + public void editKey() throws IOException { + Key key = new Key().setId(8); + service.editKey(repo, key); + verify(client).post("/repos/o/n/keys/8", key, Key.class); + } + + /** + * Delete key + * + * @throws IOException + */ + @Test + public void deleteKey() throws IOException { + service.deleteKey(repo, 88); + verify(client).delete("/repos/o/n/keys/88"); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadPayloadTest.java new file mode 100644 index 000000000..ecae49c8c --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadPayloadTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Download; +import org.eclipse.egit.github.core.event.DownloadPayload; +import org.junit.Test; + +/** + * Unit tests of {@link DownloadPayload} + */ +public class DownloadPayloadTest { + + /** + * Test default state of DownloadPayload + */ + @Test + public void defaultState() { + DownloadPayload payload = new DownloadPayload(); + assertNull(payload.getDownload()); + } + + /** + * Test updating DownloadPayload fields + */ + @Test + public void updateFields() { + DownloadPayload payload = new DownloadPayload(); + Download download = new Download().setName("download"); + assertEquals(download, payload.setDownload(download).getDownload()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadResourceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadResourceTest.java new file mode 100644 index 000000000..9b5f14504 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadResourceTest.java @@ -0,0 +1,83 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.eclipse.egit.github.core.DownloadResource; +import org.junit.Test; + +/** + * Unit tests of {@link DownloadResource} + */ +public class DownloadResourceTest { + + /** + * Test default state of download resource + */ + @Test + public void defaultState() { + DownloadResource resource = new DownloadResource(); + assertFalse(resource.isRedirect()); + assertNull(resource.getAccesskeyid()); + assertNull(resource.getAcl()); + assertNull(resource.getDescription()); + assertEquals(0, resource.getDownloadCount()); + assertNull(resource.getExpirationdate()); + assertNull(resource.getHtmlUrl()); + assertEquals(0, resource.getId()); + assertNull(resource.getMimeType()); + assertNull(resource.getName()); + assertNull(resource.getPath()); + assertNull(resource.getPolicy()); + assertNull(resource.getPrefix()); + assertNull(resource.getS3Url()); + assertNull(resource.getSignature()); + assertEquals(0, resource.getSize()); + assertNull(resource.getUrl()); + } + + /** + * Test updating download resource fields + */ + @Test + public void updateFields() { + DownloadResource resource = new DownloadResource(); + assertEquals("abc", resource.setAccesskeyid("abc").getAccesskeyid()); + assertEquals("group", resource.setAcl("group").getAcl()); + assertEquals("a download", resource.setDescription("a download") + .getDescription()); + assertEquals(5, resource.setDownloadCount(5).getDownloadCount()); + assertEquals(new Date(2500), resource.setExpirationdate(new Date(2500)) + .getExpirationdate()); + assertEquals("download.html", resource.setHtmlUrl("download.html") + .getHtmlUrl()); + assertEquals(58, resource.setId(58).getId()); + assertEquals("text/plain", resource.setMimeType("text/plain") + .getMimeType()); + assertEquals("download.jar", resource.setName("download.jar").getName()); + assertEquals("/a/b", resource.setPath("/a/b").getPath()); + assertEquals("ro", resource.setPolicy("ro").getPolicy()); + assertEquals("s3", resource.setPrefix("s3").getPrefix()); + assertEquals("/s/3", resource.setS3Url("/s/3").getS3Url()); + assertEquals("1a2b", resource.setSignature("1a2b").getSignature()); + assertEquals(12345, resource.setSize(12345).getSize()); + assertEquals("/path/dl", resource.setUrl("/path/dl").getUrl()); + assertTrue(resource.setRedirect(true).isRedirect()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadServiceTest.java new file mode 100644 index 000000000..4eaa179c9 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadServiceTest.java @@ -0,0 +1,141 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.eclipse.egit.github.core.Download; +import org.eclipse.egit.github.core.DownloadResource; +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.service.DownloadService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link DownloadService} + */ +@RunWith(MockitoJUnitRunner.class) +public class DownloadServiceTest { + + @Mock + private GitHubClient client; + + @Mock + private GitHubResponse response; + + private RepositoryId repo; + + private DownloadService service; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + service = new DownloadService(client); + doReturn(response).when(client).get(any(GitHubRequest.class)); + repo = new RepositoryId("o", "n"); + } + + /** + * Create service using default constructor + */ + @Test + public void constructor() { + assertNotNull(new DownloadService().getClient()); + } + + /** + * Get download + * + * @throws IOException + */ + @Test + public void getDownload() throws IOException { + service.getDownload(repo, 3); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/o/n/downloads/3"); + verify(client).get(request); + } + + /** + * Get downloads + * + * @throws IOException + */ + @Test + public void getDownloads() throws IOException { + service.getDownloads(repo); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/o/n/downloads")); + verify(client).get(request); + } + + /** + * Create download resource + * + * @throws IOException + */ + @Test + public void createResource() throws IOException { + Download download = new Download().setName("dl.txt"); + service.createResource(repo, download); + verify(client).post("/repos/o/n/downloads", download, + DownloadResource.class); + } + + /** + * Delete downloads + * + * @throws IOException + */ + @Test + public void deleteDownload() throws IOException { + service.deleteDownload(repo, 49); + verify(client).delete("/repos/o/n/downloads/49"); + } + + /** + * Upload resource with null resource + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void uploadResourceNullResource() throws IOException { + service.uploadResource(null, new ByteArrayInputStream(new byte[0]), 1); + } + + /** + * Upload resource with null stream + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void uploadResourceNullStream() throws IOException { + service.uploadResource(new DownloadResource(), null, 1); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadTest.java new file mode 100644 index 000000000..43bb52515 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/DownloadTest.java @@ -0,0 +1,60 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Download; +import org.junit.Test; + +/** + * Unit tests of {@link Download} + */ +public class DownloadTest { + + /** + * Test default state of download resource + */ + @Test + public void defaultState() { + Download dl = new Download(); + assertNull(dl.getDescription()); + assertEquals(0, dl.getDownloadCount()); + assertNull(dl.getHtmlUrl()); + assertEquals(0, dl.getId()); + assertNull(dl.getName()); + assertEquals(0, dl.getSize()); + assertNull(dl.getUrl()); + assertNull(dl.getContentType()); + } + + /** + * Test updating download resource fields + */ + @Test + public void updateFields() { + Download dl = new Download(); + assertEquals("a download", dl.setDescription("a download") + .getDescription()); + assertEquals(5, dl.setDownloadCount(5).getDownloadCount()); + assertEquals("download.html", dl.setHtmlUrl("download.html") + .getHtmlUrl()); + assertEquals(58, dl.setId(58).getId()); + assertEquals("download.jar", dl.setName("download.jar").getName()); + assertEquals(12345, dl.setSize(12345).getSize()); + assertEquals("/path/dl", dl.setUrl("/path/dl").getUrl()); + assertEquals("text/plain", dl.setContentType("text/plain").getContentType()); + } + +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EncodingUtilsTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EncodingUtilsTest.java new file mode 100644 index 000000000..47e99eccc --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EncodingUtilsTest.java @@ -0,0 +1,52 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import org.eclipse.egit.github.core.util.EncodingUtils; +import org.junit.Test; + +/** + * Unit tests of {@link EncodingUtils} + */ +public class EncodingUtilsTest { + + /** + * Test default constructor through anonymous sub-class + */ + @Test + public void constructor() { + assertNotNull(new EncodingUtils() { + }); + } + + /** + * Encode and decode content + */ + @Test + public void encodeDecode() { + String test = "content"; + String encoded = EncodingUtils.toBase64(test.getBytes()); + assertNotNull(encoded); + assertFalse(encoded.length() == 0); + assertFalse(test.equals(encoded)); + byte[] decoded = EncodingUtils.fromBase64(encoded); + assertNotNull(decoded); + assertFalse(decoded.length == 0); + assertEquals(test, new String(decoded)); + } + +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventFormatterTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventFormatterTest.java new file mode 100644 index 000000000..28e2fa7d1 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventFormatterTest.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.eclipse.egit.github.core.event.Event.TYPE_FOLLOW; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.client.EventFormatter; +import org.eclipse.egit.github.core.client.GsonUtils; +import org.eclipse.egit.github.core.event.Event; +import org.eclipse.egit.github.core.event.EventPayload; +import org.eclipse.egit.github.core.event.FollowPayload; +import org.junit.Test; + +/** + * Unit tests of {@link EventFormatter} + */ +public class EventFormatterTest { + + /** + * Follow event payload returned as {@link FollowPayload} + */ + @Test + public void followPayload() { + Event event = GsonUtils.fromJson("{\"type\":\"" + TYPE_FOLLOW + + "\",\"payload\":{}}", Event.class); + assertNotNull(event); + assertNotNull(event.getPayload()); + assertEquals(FollowPayload.class, event.getPayload().getClass()); + } + + /** + * Unknown event payload returned as {@link EventPayload} + */ + @Test + public void unknownPayload() { + Event event = GsonUtils.fromJson( + "{\"type\":\"NotAnEventType\",\"payload\":{}}", Event.class); + assertNotNull(event); + assertNotNull(event.getPayload()); + assertEquals(EventPayload.class, event.getPayload().getClass()); + } + + /** + * Event with missing type has payload returned as {@link EventPayload} + */ + @Test + public void missingType() { + Event event = GsonUtils.fromJson("{\"payload\":{}}", Event.class); + assertNotNull(event); + assertNotNull(event.getPayload()); + assertEquals(EventPayload.class, event.getPayload().getClass()); + } + + /** + * Missing payload + */ + @Test + public void missingPayload() { + Event event = GsonUtils.fromJson("{}", Event.class); + assertNotNull(event); + assertNull(event.getPayload()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventPayloadTest.java new file mode 100644 index 000000000..c0ffc3771 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventPayloadTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +/** + * Tests for all subclasses of EventPayload + */ +@RunWith(Suite.class) +@SuiteClasses({ CommitCommentPayloadTest.class, // + CreatePayloadTest.class, // + DeletePayloadTest.class, // + DownloadPayloadTest.class, // + FollowPayloadTest.class, // + ForkApplyPayloadTest.class, // + ForkPayloadTest.class, // + GistPayloadTest.class, // + GollumPayloadTest.class, // + IssueCommentPayloadTest.class, // + IssuesPayloadTest.class, // + MemberPayloadTest.class, // + PullRequestPayloadTest.class, // + PullRequestReviewCommentPayloadTest.class, // + PushPayloadTest.class, // + TeamAddPayloadTest.class, // + WatchPayloadTest.class }) +public class EventPayloadTest { + // EventPayload is an empty class, no tests to run. +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventRepositoryTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventRepositoryTest.java new file mode 100644 index 000000000..ccad96a75 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventRepositoryTest.java @@ -0,0 +1,47 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.event.EventRepository; +import org.junit.Test; + +/** + * Unit tests of {@link EventRepository} + */ +public class EventRepositoryTest { + + /** + * Test default state of event repository + */ + @Test + public void defaultState() { + EventRepository repo = new EventRepository(); + assertEquals(0, repo.getId()); + assertNull(repo.getName()); + assertNull(repo.getUrl()); + } + + /** + * Test updating event repository fields + */ + @Test + public void updateFields() { + EventRepository repo = new EventRepository(); + assertEquals(4, repo.setId(4).getId()); + assertEquals("repo1", repo.setName("repo1").getName()); + assertEquals("url", repo.setUrl("url").getUrl()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventServiceTest.java new file mode 100644 index 000000000..09bf42978 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventServiceTest.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.client.PageIterator; +import org.eclipse.egit.github.core.event.Event; +import org.eclipse.egit.github.core.service.EventService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link EventService} + */ +@RunWith(MockitoJUnitRunner.class) +public class EventServiceTest { + + @Mock + private GitHubClient gitHubClient; + + @Mock + private GitHubResponse response; + + private EventService eventService; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + eventService = new EventService(gitHubClient); + } + + /** + * Create service with null client + */ + @Test(expected = IllegalArgumentException.class) + public void constructorNullArgument() { + new EventService(null); + } + + /** + * Create default service + */ + @Test + public void defaultConstructor() { + assertNotNull(new EventService().getClient()); + } + + /** + * Page public events + * + * @throws IOException + */ + @Test + public void pagePublicEvents() throws IOException { + PageIterator iterator = eventService.pagePublicEvents(); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/events"), iterator + .getRequest().generateUri()); + } + + /** + * Page events for repository + * + * @throws IOException + */ + @Test + public void pageRepsitoryEvents() throws IOException { + RepositoryId repo = new RepositoryId("user", "repo"); + PageIterator iterator = eventService.pageEvents(repo); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/repos/user/repo/events"), iterator + .getRequest().generateUri()); + } + + /** + * Page events for network of repositories + * + * @throws IOException + */ + @Test + public void pageNetworkEvents() throws IOException { + RepositoryId repo = new RepositoryId("user", "repo"); + PageIterator iterator = eventService.pageNetworkEvents(repo); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/networks/user/repo/events"), iterator + .getRequest().generateUri()); + } + + /** + * Page events for org + * + * @throws IOException + */ + @Test + public void pageOrgEvents() throws IOException { + PageIterator iterator = eventService.pageOrgEvents("org"); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/orgs/org/events"), iterator + .getRequest().generateUri()); + } + + /** + * Page received events for user + * + * @throws IOException + */ + @Test + public void pageUserReceivedEvents() throws IOException { + PageIterator iterator = eventService.pageUserReceivedEvents("user"); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/users/user/received_events"), iterator + .getRequest().generateUri()); + } + + /** + * Page public received events for user + * + * @throws IOException + */ + @Test + public void pagePublicUserReceivedEvents() throws IOException { + PageIterator iterator = eventService.pageUserReceivedEvents("user", true); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/users/user/received_events/public"), iterator + .getRequest().generateUri()); + } + + /** + * Page events for user + * + * @throws IOException + */ + @Test + public void pageUserEvents() throws IOException { + PageIterator iterator = eventService.pageUserEvents("user"); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/users/user/events"), iterator + .getRequest().generateUri()); + } + + /** + * Page public events for user + * + * @throws IOException + */ + @Test + public void pagePublicUserEvents() throws IOException { + PageIterator iterator = eventService.pageUserEvents("user", true); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/users/user/events/public"), iterator + .getRequest().generateUri()); + } + + /** + * Page org events for user + * + * @throws IOException + */ + @Test + public void pageUserOrgEvents() throws IOException { + PageIterator iterator = eventService.pageUserOrgEvents("user", "org"); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/users/user/events/orgs/org"), iterator + .getRequest().generateUri()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventTest.java new file mode 100644 index 000000000..9fb6f4aa1 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/EventTest.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.eclipse.egit.github.core.User; +import org.eclipse.egit.github.core.event.Event; +import org.eclipse.egit.github.core.event.EventPayload; +import org.eclipse.egit.github.core.event.EventRepository; +import org.junit.Test; + +/** + * Unit tests of {@link Event} + */ +public class EventTest { + + /** + * Test default state of event + */ + @Test + public void defaultState() { + Event event = new Event(); + assertNull(event.getType()); + assertNull(event.getPayload()); + assertNull(event.getRepo()); + assertNull(event.getActor()); + assertNull(event.getOrg()); + assertNull(event.getCreatedAt()); + assertFalse(event.isPublic()); + assertNull(event.getId()); + } + + /** + * Test updating event fields + */ + @Test + public void updateFields() { + Event event = new Event(); + assertEquals("PushEvent", event.setType("PushEvent").getType()); + EventPayload payload = new EventPayload(); + assertEquals(payload, event.setPayload(payload).getPayload()); + EventRepository repo = new EventRepository().setName("repo"); + assertEquals(repo, event.setRepo(repo).getRepo()); + User actor = new User().setLogin("actor"); + assertEquals(actor, event.setActor(actor).getActor()); + User org = new User().setLogin("org"); + assertEquals(org, event.setOrg(org).getOrg()); + assertEquals(new Date(5000), event.setCreatedAt(new Date(5000)) + .getCreatedAt()); + assertTrue(event.setPublic(true).isPublic()); + assertEquals("123", event.setId("123").getId()); + } + + /** + * Test non-mutable created at date + */ + @Test + public void getCreatedAtReferenceMutableObject() { + Event event = new Event(); + event.setCreatedAt(new Date(11111)); + event.getCreatedAt().setTime(0); + assertTrue(event.getCreatedAt().getTime() != 0); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/FieldErrorTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/FieldErrorTest.java new file mode 100644 index 000000000..c3c48aea3 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/FieldErrorTest.java @@ -0,0 +1,51 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.FieldError; +import org.junit.Test; + +/** + * Unit tests of {@link FieldError} + */ +public class FieldErrorTest { + + /** + * Test default state of field error + */ + @Test + public void defaultState() { + FieldError error = new FieldError(); + assertNull(error.getCode()); + assertNull(error.getField()); + assertNull(error.getMessage()); + assertNull(error.getResource()); + assertNull(error.getValue()); + } + + /** + * Test updating field error fields + */ + @Test + public void updateFields() { + FieldError error = new FieldError(); + assertEquals("invalid", error.setCode("invalid").getCode()); + assertEquals("name", error.setField("name").getField()); + assertEquals("commit", error.setResource("commit").getResource()); + assertEquals("message", error.setMessage("message").getMessage()); + assertEquals("-1", error.setValue("-1").getValue()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/FollowPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/FollowPayloadTest.java new file mode 100644 index 000000000..236a57e61 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/FollowPayloadTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertEquals; + +import org.eclipse.egit.github.core.User; +import org.eclipse.egit.github.core.event.FollowPayload; +import org.junit.Test; + +/** + * Unit tests of {@link FollowPayload} + */ +public class FollowPayloadTest { + + /** + * Test default state of FollowPayload + */ + @Test + public void defaultState() { + FollowPayload payload = new FollowPayload(); + assertNull(payload.getTarget()); + } + + /** + * Test updating FollowPayload fields + */ + @Test + public void updateFields() { + FollowPayload payload = new FollowPayload(); + User target = new User().setName("target"); + assertEquals(target, payload.setTarget(target).getTarget()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ForkApplyPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ForkApplyPayloadTest.java new file mode 100644 index 000000000..4a7308c4d --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ForkApplyPayloadTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.event.ForkApplyPayload; +import org.junit.Test; + +/** + * Unit tests of {@link ForkApplyPayload} + */ +public class ForkApplyPayloadTest { + + /** + * Test default state of ForkApplyPayload + */ + @Test + public void defaultState() { + ForkApplyPayload payload = new ForkApplyPayload(); + assertNull(payload.getHead()); + assertNull(payload.getBefore()); + assertNull(payload.getAfter()); + } + + /** + * Test updating ForkApplyPayload fields + */ + @Test + public void updateFields() { + ForkApplyPayload payload = new ForkApplyPayload(); + assertEquals("head", payload.setHead("head").getHead()); + assertEquals("000", payload.setBefore("000").getBefore()); + assertEquals("001", payload.setAfter("001").getAfter()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ForkPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ForkPayloadTest.java new file mode 100644 index 000000000..a7c3e22c5 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/ForkPayloadTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.event.ForkPayload; +import org.junit.Test; + +/** + * Unit tests of {@link ForkPayload} + */ +public class ForkPayloadTest { + + /** + * Test default state of ForkPayload + */ + @Test + public void defaultState() { + ForkPayload payload = new ForkPayload(); + assertNull(payload.getForkee()); + } + + /** + * Test updating ForkPayload fields + */ + @Test + public void updateFields() { + ForkPayload payload = new ForkPayload(); + Repository forkee = new Repository().setDescription("forkee"); + assertEquals(forkee, payload.setForkee(forkee).getForkee()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistChangeStatusTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistChangeStatusTest.java new file mode 100644 index 000000000..72c52818a --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistChangeStatusTest.java @@ -0,0 +1,46 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.egit.github.core.GistChangeStatus; +import org.junit.Test; + +/** + * Unit tests of {@link GistChangeStatus} + */ +public class GistChangeStatusTest { + + /** + * Test default state of gist change status + */ + @Test + public void defaultState() { + GistChangeStatus change = new GistChangeStatus(); + assertEquals(0, change.getAdditions()); + assertEquals(0, change.getDeletions()); + assertEquals(0, change.getTotal()); + } + + /** + * Test updating gist change status fields + */ + @Test + public void updateFields() { + GistChangeStatus change = new GistChangeStatus(); + assertEquals(50, change.setAdditions(50).getAdditions()); + assertEquals(200, change.setDeletions(200).getDeletions()); + assertEquals(123, change.setTotal(123).getTotal()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistFileTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistFileTest.java new file mode 100644 index 000000000..5b78e293e --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistFileTest.java @@ -0,0 +1,49 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.GistFile; +import org.junit.Test; + +/** + * Unit tests of {@link GistFile} + */ +public class GistFileTest { + + /** + * Test default state of gist file + */ + @Test + public void defaultState() { + GistFile file = new GistFile(); + assertEquals(0, file.getSize()); + assertNull(file.getContent()); + assertNull(file.getRawUrl()); + assertNull(file.getFilename()); + } + + /** + * Test updating gist file fields + */ + @Test + public void updateFields() { + GistFile file = new GistFile(); + assertEquals(100, file.setSize(100).getSize()); + assertEquals("content", file.setContent("content").getContent()); + assertEquals("rawUrl", file.setRawUrl("rawUrl").getRawUrl()); + assertEquals("name", file.setFilename("name").getFilename()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistPayloadTest.java new file mode 100644 index 000000000..75b65d75c --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistPayloadTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertEquals; + +import org.eclipse.egit.github.core.Gist; +import org.eclipse.egit.github.core.event.GistPayload; +import org.junit.Test; + +/** + * Unit tests of {@link GistPayload} + */ +public class GistPayloadTest { + + /** + * Test default state of GistPayload + */ + @Test + public void defaultState() { + GistPayload payload = new GistPayload(); + assertNull(payload.getAction()); + assertNull(payload.getGist()); + } + + /** + * Test updating GistPayload fields + */ + @Test + public void updateFields() { + GistPayload payload = new GistPayload(); + Gist gist = new Gist().setId("id"); + assertEquals("create", payload.setAction("create").getAction()); + assertEquals(gist, payload.setGist(gist).getGist()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java new file mode 100644 index 000000000..bd3112530 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistRevisionTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.eclipse.egit.github.core.GistChangeStatus; +import org.eclipse.egit.github.core.GistRevision; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link GistRevision} + */ +public class GistRevisionTest { + + /** + * Test default state of gist revision + */ + @Test + public void defaultState() { + GistRevision revision = new GistRevision(); + assertNull(revision.getChangeStatus()); + assertNull(revision.getCommittedAt()); + assertNull(revision.getUrl()); + assertNull(revision.getUser()); + assertNull(revision.getVersion()); + } + + /** + * Test updating fields of a gist revision + */ + @Test + public void updateFields() { + GistRevision revision = new GistRevision(); + GistChangeStatus status = new GistChangeStatus(); + assertEquals(status, revision.setChangeStatus(status).getChangeStatus()); + assertEquals(new Date(5000), revision.setCommittedAt(new Date(5000)) + .getCommittedAt()); + assertEquals("url", revision.setUrl("url").getUrl()); + User user = new User().setLogin("testuser"); + assertEquals(user, revision.setUser(user).getUser()); + assertEquals("abc", revision.setVersion("abc").getVersion()); + } + + /** + * Test non-mutable committed at date + */ + @Test + public void getCreatedAReferenceMutableObject() { + GistRevision gistRevision = new GistRevision(); + Date date = new Date(10000); + gistRevision.setCommittedAt(date); + gistRevision.getCommittedAt().setTime(0); + assertTrue(gistRevision.getCommittedAt().getTime() != 0); + date.setTime(1000); + assertEquals(10000, gistRevision.getCommittedAt().getTime()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java new file mode 100644 index 000000000..b33cfc474 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java @@ -0,0 +1,538 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.egit.github.core.Comment; +import org.eclipse.egit.github.core.Gist; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.client.PageIterator; +import org.eclipse.egit.github.core.service.GistService; +import org.eclipse.egit.github.core.service.IssueService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link GistService} + */ +@RunWith(MockitoJUnitRunner.class) +public class GistServiceTest { + + @Mock + private GitHubClient gitHubClient; + + @Mock + private GitHubResponse response; + + private GistService gistService; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(gitHubClient).get(any(GitHubRequest.class)); + gistService = new GistService(gitHubClient); + } + + /** + * Create service with null client + */ + @Test(expected = IllegalArgumentException.class) + public void constructorNullArgument() { + new GistService(null); + } + + /** + * Create default service + */ + @Test + public void defaultContructor() { + assertNotNull(new GistService().getClient()); + } + + /** + * Get gist with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getGistNullId() throws IOException { + gistService.getGist(null); + } + + /** + * Get gist with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getGistEmptyId() throws IOException { + gistService.getGist(""); + } + + /** + * Get gist with valid id + * + * @throws IOException + */ + @Test + public void getGist() throws IOException { + gistService.getGist("1"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/gists/1"); + verify(gitHubClient).get(request); + } + + /** + * Delete gist with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteGistNullId() throws IOException { + gistService.deleteGist(null); + } + + /** + * Delete gist with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteGistEmptyId() throws IOException { + gistService.deleteGist(""); + } + + /** + * Delete gist with valid id + * + * @throws IOException + */ + @Test + public void deleteGist() throws IOException { + gistService.deleteGist("1"); + verify(gitHubClient).delete("/gists/1"); + } + + /** + * Star gist with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void starGistNullId() throws IOException { + gistService.starGist(null); + } + + /** + * Star gist with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void starGistEmptyId() throws IOException { + gistService.starGist(""); + } + + /** + * Star gist with valid id + * + * @throws IOException + */ + @Test + public void starGist() throws IOException { + gistService.starGist("1"); + verify(gitHubClient).put("/gists/1/star"); + } + + /** + * Unstar gist with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void unstarGistNullId() throws IOException { + gistService.unstarGist(null); + } + + /** + * Unstar gist with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void unstarGistEmptyId() throws IOException { + gistService.unstarGist(""); + } + + /** + * Unstar gist with valid id + * + * @throws IOException + */ + @Test + public void unstarGist() throws IOException { + gistService.unstarGist("1"); + verify(gitHubClient).delete("/gists/1/star"); + } + + /** + * Is gist starred with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void isStarredGistNullId() throws IOException { + gistService.isStarred(null); + } + + /** + * Is gist starred with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void isStarredGistEmptyId() throws IOException { + gistService.isStarred(""); + } + + /** + * Is gist starred with valid id + * + * @throws IOException + */ + @Test + public void isStarredGist() throws IOException { + gistService.isStarred("1"); + GitHubRequest request = new GitHubRequest(); + request.setUri("/gists/1/star"); + verify(gitHubClient).get(request); + } + + /** + * Fork gist with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void forkGistNullId() throws IOException { + gistService.forkGist(null); + } + + /** + * Fork gist with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void forkGistEmptyId() throws IOException { + gistService.forkGist(""); + } + + /** + * Fork gist with valid id + * + * @throws IOException + */ + @Test + public void forkGist() throws IOException { + gistService.forkGist("1"); + verify(gitHubClient).post("/gists/1/fork", null, Gist.class); + } + + /** + * Edit comment with null comment + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editGistCommentNullComment() throws IOException { + gistService.editComment(null); + } + + /** + * Edit comment + * + * @throws IOException + */ + @Test + public void editGistComment() throws IOException { + Comment comment = new Comment(); + comment.setId(48).setBody("new body"); + gistService.editComment(comment); + verify(gitHubClient).post("/gists/comments/48", comment, Comment.class); + } + + /** + * Get gist comment + * + * @throws IOException + */ + @Test + public void getGistComment() throws IOException { + gistService.getComment(59); + GitHubRequest request = new GitHubRequest(); + request.setUri("/gists/comments/59"); + verify(gitHubClient).get(request); + } + + /** + * Delete gist comment + * + * @throws IOException + */ + @Test + public void deleteGistComment() throws IOException { + gistService.deleteComment(1234); + verify(gitHubClient).delete("/gists/comments/1234"); + } + + /** + * Get starred gists + * + * @throws IOException + */ + @Test + public void getStarredGists() throws IOException { + List starred = gistService.getStarredGists(); + assertNotNull(starred); + assertEquals(0, starred.size()); + } + + /** + * Get iterator for starred gists + * + * @throws IOException + */ + @Test + public void pageStarredGists() throws IOException { + PageIterator iterator = gistService.pageStarredGists(); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/gists/starred"), iterator.getRequest() + .generateUri()); + } + + /** + * Get gists for null login name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getGistsNullUser() throws IOException { + gistService.getGists(null); + } + + /** + * Get gists for empty login name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getGistsEmptyUser() throws IOException { + gistService.getGists(""); + } + + /** + * Get gists for valid login name + * + * @throws IOException + */ + @Test + public void getGistsOK() throws IOException { + gistService.getGists("test_user"); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/users/test_user/gists")); + verify(gitHubClient).get(request); + } + + /** + * Create gist with null model + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createGistNullGist() throws IOException { + gistService.createGist(null); + } + + /** + * Get gist with null user + * + * @throws IOException + */ + @Test + public void createGistNullOwner() throws IOException { + Gist gist = new Gist(); + gist.setOwner(null); + gistService.createGist(gist); + verify(gitHubClient).post("/gists", gist, Gist.class); + } + + /** + * Update null gist + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void updateGistNullGist() throws IOException { + gistService.updateGist(null); + } + + /** + * Update gist with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void updateGistNullId() throws IOException { + Gist gist = new Gist(); + gist.setId(null); + gistService.updateGist(gist); + } + + /** + * Update valid gist + * + * @throws IOException + */ + @Test + public void updateGistOK() throws IOException { + Gist gist = new Gist(); + gist.setId("123"); + gistService.updateGist(gist); + verify(gitHubClient).post("/gists/123", gist, Gist.class); + } + + /** + * Create comment for with null gist id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentNullGistId() throws IOException { + gistService.createComment(null, "not null"); + } + + /** + * Create null comment + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentNullComment() throws IOException { + gistService.createComment("not null", null); + } + + /** + * Create valid comment + * + * @throws IOException + */ + @Test + public void createCommentOK() throws IOException { + gistService.createComment("1", "test_comment"); + + Map params = new HashMap(1, 1); + params.put(IssueService.FIELD_BODY, "test_comment"); + verify(gitHubClient).post("/gists/1/comments", params, Comment.class); + } + + /** + * Get comments for null gist id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsNullGistId() throws IOException { + gistService.getComments(null); + } + + /** + * Get comment with valid gist id + * + * @throws IOException + */ + @Test + public void getCommentsOK() throws IOException { + gistService.getComments("1"); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/gists/1/comments")); + verify(gitHubClient).get(request); + } + + /** + * Page gists with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void pageUserGistsNullId() throws IOException { + gistService.pageGists(null); + } + + /** + * Page gists with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void pageUserGistsEmptyId() throws IOException { + gistService.pageGists(""); + } + + /** + * Page gists with valid user + * + * @throws IOException + */ + @Test + public void pageUserGists() throws IOException { + PageIterator iterator = gistService.pageGists("user"); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/users/user/gists"), iterator.getRequest() + .generateUri()); + } + + /** + * Page public gists + * + * @throws IOException + */ + @Test + public void pagePublicGists() throws IOException { + PageIterator iterator = gistService.pagePublicGists(); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java new file mode 100644 index 000000000..be9c34e01 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistTest.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Collections; +import java.util.Date; + +import org.eclipse.egit.github.core.Gist; +import org.eclipse.egit.github.core.GistFile; +import org.eclipse.egit.github.core.GistRevision; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link Gist} + */ +public class GistTest { + + /** + * Test default state of gist + */ + @Test + public void defaultState() { + Gist gist = new Gist(); + assertEquals(0, gist.getComments()); + assertNull(gist.getCreatedAt()); + assertNull(gist.getDescription()); + assertNull(gist.getFiles()); + assertNull(gist.getGitPullUrl()); + assertNull(gist.getGitPushUrl()); + assertNull(gist.getHistory()); + assertNull(gist.getHtmlUrl()); + assertNull(gist.getId()); + assertNull(gist.getUpdatedAt()); + assertNull(gist.getUrl()); + assertNull(gist.getOwner()); + assertNull(gist.getOwner()); + assertFalse(gist.isPublic()); + } + + /** + * Test updating gist fields + */ + @Test + public void updateFields() { + Gist gist = new Gist(); + assertEquals(3, gist.setComments(3).getComments()); + assertEquals(new Date(5000), gist.setCreatedAt(new Date(5000)) + .getCreatedAt()); + assertEquals("desc", gist.setDescription("desc").getDescription()); + assertEquals(Collections.emptyMap(), + gist.setFiles(Collections. emptyMap()) + .getFiles()); + assertEquals("pull", gist.setGitPullUrl("pull").getGitPullUrl()); + assertEquals("push", gist.setGitPushUrl("push").getGitPushUrl()); + assertEquals(Collections.emptyList(), + gist.setHistory(Collections. emptyList()) + .getHistory()); + assertEquals("html", gist.setHtmlUrl("html").getHtmlUrl()); + assertEquals("id", gist.setId("id").getId()); + assertEquals(new Date(1000), gist.setUpdatedAt(new Date(1000)) + .getUpdatedAt()); + assertEquals("url", gist.setUrl("url").getUrl()); + User user = new User().setLogin("use"); + assertEquals(user, gist.setOwner(user).getOwner()); + assertTrue(gist.setPublic(true).isPublic()); + } + + /** + * Test non-mutable created at date + */ + @Test + public void getCreatedAtReferenceMutableObject() { + Gist gist = new Gist(); + gist.setCreatedAt(new Date(11111)); + gist.getCreatedAt().setTime(0); + assertTrue(gist.getCreatedAt().getTime() != 0); + } + + /** + * Test non-mutable updated at date + */ + @Test + public void getUpdatedAtReferenceMutableObject() { + Gist gist = new Gist(); + gist.setUpdatedAt(new Date(22222)); + gist.getUpdatedAt().setTime(0); + assertTrue(gist.getUpdatedAt().getTime() != 0); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java new file mode 100644 index 000000000..8f1bd7083 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.IGitHubConstants; +import org.junit.Test; + +/** + * Unit tests of {@link GitHubClient} + */ +public class GitHubClientTest { + + private static class PrefixClient extends GitHubClient { + + public PrefixClient(String host) { + super(host); + } + + String uri(String uri) { + return super.configureUri(uri); + } + } + + /** + * Verify prefix with API v3 host + */ + @Test + public void prefixHostApiV3() { + PrefixClient client = new PrefixClient(IGitHubConstants.HOST_API); + assertEquals("/api/v3/repos/o/n", client.uri("/api/v3/repos/o/n")); + assertEquals("/repos/o/n", client.uri("/repos/o/n")); + assertEquals("/api/v2/json/repos/search/test", + client.uri("/api/v2/json/repos/search/test")); + } + + /** + * Verify prefix with localhost + */ + @Test + public void prefixLocalhost() { + PrefixClient client = new PrefixClient("localhost"); + assertEquals("/api/v3/repos/o/n", client.uri("/repos/o/n")); + assertEquals("/api/v3/repos/o/n", client.uri("/api/v3/repos/o/n")); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GollumPageTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GollumPageTest.java new file mode 100644 index 000000000..8cba74388 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GollumPageTest.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertEquals; + +import org.eclipse.egit.github.core.GollumPage; +import org.junit.Test; + +/** + * Unit tests of {@link GollumPage} + */ +public class GollumPageTest { + + /** + * Test default state of GollumPage + */ + @Test + public void defaultState() { + GollumPage GollumPage = new GollumPage(); + assertNull(GollumPage.getAction()); + assertNull(GollumPage.getHtmlUrl()); + assertNull(GollumPage.getPageName()); + assertNull(GollumPage.getSha()); + assertNull(GollumPage.getTitle()); + } + + /** + * Test updating GollumPage fields + */ + @Test + public void updateFields() { + GollumPage GollumPage = new GollumPage(); + assertEquals("create", GollumPage.setAction("create").getAction()); + assertEquals("url://a", GollumPage.setHtmlUrl("url://a").getHtmlUrl()); + assertEquals("page", GollumPage.setPageName("page").getPageName()); + assertEquals("000", GollumPage.setSha("000").getSha()); + assertEquals("title", GollumPage.setTitle("title").getTitle()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GollumPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GollumPayloadTest.java new file mode 100644 index 000000000..49910fb48 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GollumPayloadTest.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.egit.github.core.GollumPage; +import org.eclipse.egit.github.core.event.GollumPayload; +import org.junit.Test; + +/** + * Unit tests of {@link GollumPayload} + */ +public class GollumPayloadTest { + + /** + * Test default state of GollumPayload + */ + @Test + public void defaultState() { + GollumPayload payload = new GollumPayload(); + assertNull(payload.getPages()); + } + + /** + * Test updating GollumPayload fields + */ + @Test + public void updateFields() { + GollumPayload payload = new GollumPayload(); + List pages = new ArrayList(); + pages.add(new GollumPage().setPageName("page")); + assertEquals(pages, payload.setPages(pages).getPages()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GsonUtilsTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GsonUtilsTest.java new file mode 100644 index 000000000..b303cbd1f --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GsonUtilsTest.java @@ -0,0 +1,73 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +import org.eclipse.egit.github.core.Blob; +import org.eclipse.egit.github.core.client.GsonUtils; +import org.junit.Test; + +/** + * Unit tests of {@link GsonUtils} + */ +public class GsonUtilsTest { + + /** + * Get Gson instances + */ + @Test + public void getGson() { + assertNotNull(GsonUtils.getGson()); + assertNotNull(GsonUtils.getGson(true)); + assertNotNull(GsonUtils.getGson(false)); + assertNotSame(GsonUtils.getGson(true), GsonUtils.getGson(false)); + } + + /** + * Create Gson instances + */ + @Test + public void createGson() { + assertNotNull(GsonUtils.createGson()); + assertNotNull(GsonUtils.createGson(true)); + assertNotNull(GsonUtils.createGson(false)); + assertNotSame(GsonUtils.createGson(true), GsonUtils.createGson(false)); + } + + /** + * Serialize objects with all null fields + */ + @Test + public void noSeriazlizeNulls() { + Blob blob = new Blob(); + String json = GsonUtils.toJson(blob, false); + assertEquals("{}", json); + } + + /** + * Serialize objects with all null fields + */ + @Test + public void seriazlizeNulls() { + Blob blob = new Blob(); + String json = GsonUtils.toJson(blob, true); + assertNotNull(json); + assertTrue(json.length() > 2); + assertFalse("{}".equals(json)); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IdTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IdTest.java new file mode 100644 index 000000000..479193d0d --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IdTest.java @@ -0,0 +1,43 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Id; +import org.junit.Test; + +/** + * Unit tests of {@link Id} + */ +public class IdTest { + + /** + * Test default state of id + */ + @Test + public void defaultState() { + Id id = new Id(); + assertNull(id.getId()); + } + + /** + * Test updating field of id + */ + @Test + public void updateField() { + Id id = new Id(); + assertEquals("12345", id.setId("12345").getId()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueCommentPayloadTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueCommentPayloadTest.java new file mode 100644 index 000000000..e093ed3b0 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueCommentPayloadTest.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jason Tsay (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.egit.github.core.Comment; +import org.eclipse.egit.github.core.Issue; +import org.eclipse.egit.github.core.event.IssueCommentPayload; +import org.junit.Test; + +/** + * Unit tests of {@link IssueCommentPayload} + */ +public class IssueCommentPayloadTest { + + /** + * Test default state of IssueCommentPayload + */ + @Test + public void defaultState() { + IssueCommentPayload payload = new IssueCommentPayload(); + assertNull(payload.getAction()); + assertNull(payload.getIssue()); + assertNull(payload.getComment()); + } + + /** + * Test updating IssueCommentPayload fields + */ + @Test + public void updateFields() { + IssueCommentPayload payload = new IssueCommentPayload(); + Issue issue = new Issue().setTitle("issue"); + Comment comment = new Comment().setBody("comment"); + assertEquals("create", payload.setAction("create").getAction()); + assertEquals(issue, payload.setIssue(issue).getIssue()); + assertEquals(comment, payload.setComment(comment).getComment()); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueEventTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueEventTest.java new file mode 100644 index 000000000..6f62662df --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueEventTest.java @@ -0,0 +1,90 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import java.util.Date; + +import org.eclipse.egit.github.core.Issue; +import org.eclipse.egit.github.core.IssueEvent; +import org.eclipse.egit.github.core.Label; +import org.eclipse.egit.github.core.Milestone; +import org.eclipse.egit.github.core.Rename; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link IssueEvent} + */ +public class IssueEventTest { + + /** + * Test default state of issue event + */ + @Test + public void defaultState() { + IssueEvent event = new IssueEvent(); + assertEquals(0, event.getId()); + assertNull(event.getUrl()); + assertNull(event.getActor()); + assertNull(event.getCommitId()); + assertNull(event.getEvent()); + assertNull(event.getCreatedAt()); + assertNull(event.getLabel()); + assertNull(event.getAssignee()); + assertNull(event.getMilestone()); + assertNull(event.getRename()); + assertNull(event.getIssue()); + } + + /** + * Test updating issue event fields + */ + @Test + public void updateFields() { + IssueEvent event = new IssueEvent(); + assertEquals(4356, event.setId(4356).getId()); + assertEquals("url://a", event.setUrl("url://a").getUrl()); + User actor = new User().setName("Act Tor"); + assertEquals(actor, event.setActor(actor).getActor()); + assertEquals("a12b", event.setCommitId("a12b").getCommitId()); + assertEquals(IssueEvent.TYPE_CLOSED, event.setEvent("closed").getEvent()); + assertEquals(new Date(60000), event.setCreatedAt(new Date(60000)) + .getCreatedAt()); + Label label = new Label().setName("Lab El").setColor("563d7c"); + assertEquals(label, event.setLabel(label).getLabel()); + User assignee = new User().setName("Assig Nee"); + assertEquals(assignee, event.setAssignee(assignee).getAssignee()); + Milestone milestone = new Milestone().setTitle("Milestone"); + assertEquals(milestone, event.setMilestone(milestone).getMilestone()); + Rename rename = new Rename().setFrom("from").setTo("to"); + assertEquals(rename, event.setRename(rename).getRename()); + Issue issue = new Issue().setNumber(30); + assertEquals(issue, event.setIssue(issue).getIssue()); + } + + /** + * Test non-mutable created at date + */ + @Test + public void nonMutableCreatedAt() { + IssueEvent event = new IssueEvent(); + Date date = new Date(1000); + event.setCreatedAt(date); + date.setTime(0); + assertFalse(date.equals(event.getCreatedAt())); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java new file mode 100644 index 000000000..d63cb29ea --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueServiceTest.java @@ -0,0 +1,919 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.egit.github.core.Comment; +import org.eclipse.egit.github.core.Issue; +import org.eclipse.egit.github.core.IssueEvent; +import org.eclipse.egit.github.core.RepositoryId; +import org.eclipse.egit.github.core.RepositoryIssue; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.client.GitHubRequest; +import org.eclipse.egit.github.core.client.GitHubResponse; +import org.eclipse.egit.github.core.client.PageIterator; +import org.eclipse.egit.github.core.service.IssueService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit tests of {@link IssueService} + */ +@RunWith(MockitoJUnitRunner.class) +public class IssueServiceTest { + + @Mock + private GitHubClient gitHubClient; + + @Mock + private GitHubResponse response; + + private IssueService issueService; + + /** + * Test case set up + * + * @throws IOException + */ + @Before + public void before() throws IOException { + doReturn(response).when(gitHubClient).get(any(GitHubRequest.class)); + issueService = new IssueService(gitHubClient); + } + + /** + * Create issue service with null client + */ + @Test(expected = IllegalArgumentException.class) + public void constructorNullArgument() { + new IssueService(null); + } + + /** + * Create issue service default constructor + */ + @Test + public void defaultConstructor() { + assertNotNull(new IssueService().getClient()); + } + + /** + * Get issue with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueNullUser() throws IOException { + issueService.getIssue(null, "not null", "not null"); + } + + /** + * Get issue with null repository id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueNullRepositoryId() throws IOException { + issueService.getIssue(null, 1); + } + + /** + * Get issue with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueEmptyUser() throws IOException { + issueService.getIssue("", "repo", "not null"); + } + + /** + * Get issue with null name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueNullRepositoryName() throws IOException { + issueService.getIssue("not null", null, "not null"); + } + + /** + * Get issue with empty name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueEmptyRepositoryName() throws IOException { + issueService.getIssue("user", "", "not null"); + } + + /** + * Get issue with null id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueNullId() throws IOException { + issueService.getIssue("not null", "not null", null); + } + + /** + * Get issue with empty id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssueEmptyId() throws IOException { + issueService.getIssue("not null", "not null", ""); + } + + /** + * Get issue with valid parameters + * + * @throws IOException + */ + @Test + public void getIssue() throws IOException { + issueService.getIssue("tu", "tr", 3); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/tu/tr/issues/3"); + verify(gitHubClient).get(request); + } + + /** + * Get issue with valid parameters + * + * @throws IOException + */ + @Test + public void getIssueWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("tu", "tr"); + issueService.getIssue(id, 3); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/tu/tr/issues/3"); + verify(gitHubClient).get(request); + } + + /** + * Get issue comments with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsNullUser() throws IOException { + issueService.getComments(null, "not null", 1); + } + + /** + * Get issue comments with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsEmptyUser() throws IOException { + issueService.getComments("", "not null", 2); + } + + /** + * Get issue comments with null name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsNullRepositoryName() throws IOException { + issueService.getComments("not null", null, 3); + } + + /** + * Get issue comments with null repository id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsNullRepositoryId() throws IOException { + issueService.getComments(null, 3); + } + + /** + * Get issue comments with empty name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsEmptyRepositoryName() throws IOException { + issueService.getComments("not null", "", 3); + } + + /** + * Get issue comments with null issue id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsNullId() throws IOException { + issueService.getComments("not null", "not null", null); + } + + /** + * Get issue comments with empty issue id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getCommentsEmptyId() throws IOException { + issueService.getComments("not null", "not null", ""); + } + + /** + * Get issue comments with valid parameters + * + * @throws IOException + */ + @Test + public void getComments() throws IOException { + issueService.getComments("tu", "tr", 4); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/tu/tr/issues/4/comments")); + verify(gitHubClient).get(request); + } + + /** + * Get issue comments with valid parameters + * + * @throws IOException + */ + @Test + public void getCommentsWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("tu", "tr"); + issueService.getComments(id, 4); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/tu/tr/issues/4/comments")); + verify(gitHubClient).get(request); + } + + /** + * Get issues with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssuesNullUser() throws IOException { + issueService.getIssues(null, "not null", null); + } + + /** + * Get issues with null repository id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssuesNullRepositoryId() throws IOException { + issueService.getIssues(null, null); + } + + /** + * Get issues with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssuesEmptyUser() throws IOException { + issueService.getIssues("", "not null", null); + } + + /** + * Get issues with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssuesNullRepositoryName() throws IOException { + issueService.getIssues("not null", null, null); + } + + /** + * Get issues with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void getIssuesEmptyRepositoryName() throws IOException { + issueService.getIssues("not null", "", null); + } + + /** + * Get issues with valid parameters + * + * @throws IOException + */ + @Test + public void getIssues() throws IOException { + issueService.getIssues("tu", "tr", null); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/tu/tr/issues")); + verify(gitHubClient).get(request); + } + + /** + * Get issues with valid parameters + * + * @throws IOException + */ + @Test + public void getIssuesRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("tu", "tr"); + issueService.getIssues(id, null); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils.page("/repos/tu/tr/issues")); + verify(gitHubClient).get(request); + } + + /** + * Create issue with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createIssueNullUser() throws IOException { + issueService.createIssue(null, "not null", new Issue()); + } + + /** + * Create issue with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createIssueEmptyUser() throws IOException { + issueService.createIssue("", "not null", new Issue()); + } + + /** + * Create issue with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createIssueNullRepositoryName() throws IOException { + issueService.createIssue("not null", null, null); + } + + /** + * Create issue with empty repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createIssueEmptyRepositoryName() throws IOException { + issueService.createIssue("not null", "", new Issue()); + } + + /** + * Create issue with null issue + * + * @throws IOException + */ + @Test + public void createIssueNullIssue() throws IOException { + issueService.createIssue("test_user", "test_repository", null); + verify(gitHubClient).post("/repos/test_user/test_repository/issues", + new HashMap(), Issue.class); + } + + /** + * Create issue with null issue + * + * @throws IOException + */ + @Test + public void createIssueNullIssueWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("tu", "tr"); + issueService.createIssue(id, null); + verify(gitHubClient).post("/repos/tu/tr/issues", + new HashMap(), Issue.class); + } + + /** + * Edit issue with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editIssueNullUser() throws IOException { + issueService.editIssue(null, "not null", new Issue()); + } + + /** + * Edit issue with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editIssueEmptyUser() throws IOException { + issueService.editIssue("", "not null", new Issue()); + } + + /** + * Edit issue with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editIssueNullRepositoryName() throws IOException { + issueService.editIssue("not null", null, new Issue()); + } + + /** + * Edit issue with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editIssueEmptyRepositoryName() throws IOException { + issueService.editIssue("not null", "", new Issue()); + } + + /** + * Edit issue with null issue + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editIssueNullIssue() throws IOException { + issueService.editIssue("not null", "not null", null); + } + + /** + * Edit issue with valid parameters + * + * @throws IOException + */ + @Test + public void editIssue() throws IOException { + Issue issue = new Issue(); + issue.setNumber(1); + issue.setTitle("test_title"); + issue.setBody("test_body"); + issue.setState("test_state"); + issueService.editIssue("test_user", "test_repository", issue); + + Map params = new HashMap(); + params.put(IssueService.FIELD_TITLE, "test_title"); + params.put(IssueService.FIELD_BODY, "test_body"); + params.put(IssueService.FILTER_STATE, "test_state"); + verify(gitHubClient).post("/repos/test_user/test_repository/issues/1", + params, Issue.class); + } + + /** + * Edit issue with valid parameters + * + * @throws IOException + */ + @Test + public void editIssueWithRepositoryId() throws IOException { + Issue issue = new Issue(); + issue.setNumber(1); + issue.setTitle("test_title"); + issue.setBody("test_body"); + issue.setState("test_state"); + RepositoryId id = new RepositoryId("tu", "tr"); + issueService.editIssue(id, issue); + + Map params = new HashMap(); + params.put(IssueService.FIELD_TITLE, "test_title"); + params.put(IssueService.FIELD_BODY, "test_body"); + params.put(IssueService.FILTER_STATE, "test_state"); + verify(gitHubClient).post("/repos/tu/tr/issues/1", params, Issue.class); + } + + /** + * Create issue comment with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentNullUser() throws IOException { + issueService.createComment(null, "not null", 1, "not null"); + } + + /** + * Create issue comment with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentEmptyUser() throws IOException { + issueService.createComment("", "not null", 2, "not null"); + } + + /** + * Create issue comment with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentNullRepositoryName() throws IOException { + issueService.createComment("not null", null, 3, "not null"); + } + + /** + * Create issue comment with empty repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentEmptyRepositoryName() throws IOException { + issueService.createComment("not null", "", 4, "not null"); + } + + /** + * Create issue comment with null issue id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentNullIssueId() throws IOException { + issueService.createComment("not null", "not null", null, "not null"); + } + + /** + * Create issue comment with empty issue id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createCommentEmptyIssueId() throws IOException { + issueService.createComment("not null", "not null", "", "not null"); + } + + /** + * Create issue comment with valid parameters + * + * @throws IOException + */ + @Test + public void createComment() throws IOException { + issueService.createComment("test_user", "test_repository", 1, + "test_comment"); + + Map params = new HashMap(); + params.put(IssueService.FIELD_BODY, "test_comment"); + verify(gitHubClient).post( + "/repos/test_user/test_repository/issues/1/comments", params, + Comment.class); + } + + /** + * Create issue comment with valid parameters + * + * @throws IOException + */ + @Test + public void createCommentWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("tu", "tr"); + issueService.createComment(id, 1, "test_comment"); + + Map params = new HashMap(); + params.put(IssueService.FIELD_BODY, "test_comment"); + verify(gitHubClient).post("/repos/tu/tr/issues/1/comments", params, + Comment.class); + } + + /** + * Delete comment with null user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteCommentNullUser() throws IOException { + issueService.deleteComment(null, "repo", 1); + } + + /** + * Delete comment with empty user + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteCommentEmptyUser() throws IOException { + issueService.deleteComment("", "repo", 1); + } + + /** + * Delete comment with null repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteCommentNullRepositoryName() throws IOException { + issueService.deleteComment("user", null, 1); + } + + /** + * Delete comment with empty repository name + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteCommentEmptyRepositoryName() throws IOException { + issueService.deleteComment("user", "", 1); + } + + /** + * Delete comment with null comment id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteCommentNullId() throws IOException { + issueService.deleteComment("user", "repo", null); + } + + /** + * Delete comment with empty comment id + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void deleteCommentEmptyId() throws IOException { + issueService.deleteComment("user", "repo", ""); + } + + /** + * Delete issue comment + * + * @throws IOException + */ + @Test + public void deleteComment() throws IOException { + issueService.deleteComment("user", "repo", 1); + verify(gitHubClient).delete("/repos/user/repo/issues/comments/1"); + } + + /** + * Delete issue comment + * + * @throws IOException + */ + @Test + public void deleteCommentWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.deleteComment(id, 1); + verify(gitHubClient).delete("/repos/user/repo/issues/comments/1"); + } + + /** + * Page issues for current user + * + * @throws IOException + */ + @Test + public void pageIssues() throws IOException { + PageIterator iterator = issueService.pageIssues(); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/issues"), iterator.getRequest().generateUri()); + } + + /** + * Page issues for repository + * + * @throws IOException + */ + @Test + public void pageRepsitoryIssues() throws IOException { + PageIterator iterator = issueService.pageIssues("user", "repo"); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/repos/user/repo/issues"), iterator + .getRequest().generateUri()); + } + + /** + * Page issues for repository + * + * @throws IOException + */ + @Test + public void pageRepsitoryIssuesWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + PageIterator iterator = issueService.pageIssues(id); + assertNotNull(iterator); + assertTrue(iterator.hasNext()); + assertEquals(Utils.page("/repos/user/repo/issues"), iterator + .getRequest().generateUri()); + } + + /** + * Get issues for current user + * + * @throws IOException + */ + @Test + public void getCurrentUserIssues() throws IOException { + List issues = issueService.getIssues(); + assertNotNull(issues); + assertTrue(issues.isEmpty()); + } + + /** + * Page all issue events for repository + * + * @throws IOException + */ + @Test + public void pageEvents() throws IOException { + PageIterator iter = issueService.pageEvents("user", "repo"); + assertNotNull(iter); + assertTrue(iter.hasNext()); + assertEquals(Utils.page("/repos/user/repo/issues/events"), iter + .getRequest().generateUri()); + } + + /** + * Page issue events for repository + * + * @throws IOException + */ + @Test + public void pageIssueEvents() throws IOException { + PageIterator iter = issueService.pageIssueEvents("user", + "repo", 16); + assertNotNull(iter); + assertTrue(iter.hasNext()); + assertEquals(Utils.page("/repos/user/repo/issues/16/events"), iter + .getRequest().generateUri()); + } + + /** + * Get issue event + * + * @throws IOException + */ + @Test + public void getIssueEvent() throws IOException { + issueService.getIssueEvent("user", "repo", 4399); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/user/repo/issues/events/4399"); + verify(gitHubClient).get(request); + } + + /** + * Get issue comment + * + * @throws IOException + */ + @Test + public void getIssueComment() throws IOException { + issueService.getComment("user", "repo", 38); + GitHubRequest request = new GitHubRequest(); + request.setUri("/repos/user/repo/issues/comments/38"); + verify(gitHubClient).get(request); + } + + /** + * Edit issue comment with null comment + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void editIssueCommentNullComment() throws IOException { + issueService.editComment("user", "repo", null); + } + + /** + * Edit issue comment + * + * @throws IOException + */ + @Test + public void editIssueComment() throws IOException { + Comment comment = new Comment().setId(29).setBody("new body"); + issueService.editComment("user", "repo", comment); + verify(gitHubClient).post("/repos/user/repo/issues/comments/29", + comment, Comment.class); + } + + /** + * Edit issue comment + * + * @throws IOException + */ + @Test + public void editIssueCommentWithRepositoryId() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + Comment comment = new Comment().setId(44).setBody("new body"); + issueService.editComment(id, comment); + verify(gitHubClient).post("/repos/user/repo/issues/comments/44", + comment, Comment.class); + } + + /** + * Search issues with null repository + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void searchIssuesNullRepository() throws IOException { + issueService.searchIssues(null, "open", "test"); + } + + /** + * Search issues with null query + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void searchIssueNullQuery() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.searchIssues(id, "open", null); + } + + /** + * Search issues with empty query + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void searchIssueEmptyQuery() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.searchIssues(id, "open", ""); + } + + /** + * Search issues with null state + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void searchIssueNullState() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.searchIssues(id, null, "test"); + } + + /** + * Search issues with empty state + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void searchIssueEmptyState() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.searchIssues(id, "", "test"); + } + + /** + * Search issues + * + * @throws IOException + */ + @Test + public void searchIssues() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.searchIssues(id, "closed", "test"); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils + .page("/legacy/issues/search/user/repo/closed/test")); + verify(gitHubClient).get(request); + } + + /** + * Search issues with query that needs escaping + * + * @throws IOException + */ + @Test + public void searchEscaped() throws IOException { + RepositoryId id = new RepositoryId("user", "repo"); + issueService.searchIssues(id, "open", "a and a."); + GitHubRequest request = new GitHubRequest(); + request.setUri(Utils + .page("/legacy/issues/search/user/repo/open/a%20and%20a%2E")); + verify(gitHubClient).get(request); + } +} diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java new file mode 100644 index 000000000..6ce58eb99 --- /dev/null +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/IssueTest.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2011 Christian Trutz + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christian Trutz - initial API and implementation + *******************************************************************************/ +package org.eclipse.egit.github.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Date; + +import org.eclipse.egit.github.core.Issue; +import org.eclipse.egit.github.core.Label; +import org.eclipse.egit.github.core.Milestone; +import org.eclipse.egit.github.core.PullRequest; +import org.eclipse.egit.github.core.User; +import org.junit.Test; + +/** + * Unit tests of {@link Issue} + */ +public class IssueTest { + + /** + * Test default state of issue + */ + @Test + public void defaultState() { + Issue issue = new Issue(); + assertNull(issue.getAssignee()); + assertNull(issue.getBody()); + assertNull(issue.getBodyHtml()); + assertNull(issue.getBodyText()); + assertNull(issue.getClosedAt()); + assertEquals(0, issue.getComments()); + assertNull(issue.getCreatedAt()); + assertNull(issue.getHtmlUrl()); + assertNull(issue.getLabels()); + assertNull(issue.getMilestone()); + assertEquals(0, issue.getNumber()); + assertNull(issue.getPullRequest()); + assertNull(issue.getState()); + assertNull(issue.getTitle()); + assertNull(issue.getUpdatedAt()); + assertNull(issue.getUrl()); + assertNull(issue.getUser()); + assertNotNull(issue.toString()); + assertEquals(0, issue.getId()); + assertNull(issue.getClosedBy()); + } + + /** + * Test updating issue fields + */ + @Test + public void updateFields() { + Issue issue = new Issue(); + User assignee = new User().setLogin("assignee"); + assertEquals(assignee, issue.setAssignee(assignee).getAssignee()); + assertEquals("body", issue.setBody("body").getBody()); + assertEquals("", issue.setBodyHtml("").getBodyHtml()); + assertEquals("text", issue.setBodyText("text").getBodyText()); + assertEquals(new Date(1000), issue.setClosedAt(new Date(1000)) + .getClosedAt()); + assertEquals(5, issue.setComments(5).getComments()); + assertEquals(new Date(2000), issue.setCreatedAt(new Date(2000)) + .getCreatedAt()); + assertEquals("html", issue.setHtmlUrl("html").getHtmlUrl()); + assertEquals(new ArrayList