Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fsteeg/egit-github
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: srgcode/egit-github
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Mar 29, 2011

  1. HTTP 201 (HTTP Created) is not handled as error

    GitHUb issues can be created now.
    
    Bug: 340900
    Change-Id: Ieac3108163f4e7f1b5fa78b369e3140244dee04b
    Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
    smilebase committed Mar 29, 2011
    Copy the full SHA
    16c98e3 View commit details

Commits on Apr 4, 2011

  1. Merge "HTTP 201 (HTTP Created) is not handled as error"

    caniszczyk authored and Code Review committed Apr 4, 2011
    Copy the full SHA
    b4735b0 View commit details

Commits on Apr 5, 2011

  1. Add comment support to GitHub task editor

    Adding new comments on existing issues is implemented now.
    
    Bug: 340901
    Change-Id: I896ace16cc698e4b51ebb61e5a2732a874789dfb
    Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
    smilebase committed Apr 5, 2011
    Copy the full SHA
    728bc02 View commit details
  2. New launch file

    Simplify starting Eclipse instance including egit-github plugins
    
    Change-Id: I789ecb7684bac1beeef227f9aeee602e3ebfdca8
    Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
    smilebase committed Apr 5, 2011
    Copy the full SHA
    5da76f5 View commit details

Commits on Apr 7, 2011

  1. Add support for creating Gists

    Supports creating gists on selections with files and on
    a selected file.
    
    Change-Id: Iab9b2a3892aaf6e753d8fcde77917c8d7347e8d0
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    caniszczyk committed Apr 7, 2011
    Copy the full SHA
    a193f51 View commit details
  2. Add missing credentials on GitHubService.showIssue

    This fixes 401 exceptions being thrown when issue in private
    repository is refreshed in task editor.
    
    Change-Id: Ie0fc780a8e439699a203184070de5cf4fd06c56e
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    kevinsawicki authored and caniszczyk committed Apr 7, 2011
    Copy the full SHA
    1eea7cf View commit details
  3. Fix incorrect date format with swapped month and minute

    Change-Id: Ie6cf75c961eafcf37d31cedf50a0ae2b6586677f
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 7, 2011
    Copy the full SHA
    3cf270b View commit details
  4. Change summary attribute to type short rich text

    This improves the appearance in the summary editor part.
    
    Change-Id: I11e0e907321d1ec2558f1f568f1b191134a155e9
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 7, 2011
    Copy the full SHA
    0cc4165 View commit details
  5. Use proper GitHub logo

    Change-Id: If72b62fd5e2389f3bcf9e0db0dc999a9284b0fc3
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    caniszczyk committed Apr 7, 2011
    Copy the full SHA
    b31532a View commit details
  6. Close reader and use StringBuilder instead of StringBuffer.

    Change-Id: I33506b4399918c4b4194b73ed6cb1f34a26b286f
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    kevinsawicki committed Apr 7, 2011
    Copy the full SHA
    37149b8 View commit details
  7. Copy the full SHA
    f2c6f29 View commit details
  8. Add support for converting JSON dates to Java dates.

    Change-Id: If328b7023e0b8cdc4f19f23fd473b4189b2ffe4e
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    kevinsawicki committed Apr 7, 2011
    Copy the full SHA
    7bb025d View commit details

Commits on Apr 8, 2011

  1. Add ability to view comments on an issue.

    Adds service support for getting a list of comments and maps
    them as task attributes.
    
    Bug: 340901
    Change-Id: I0210346e20125e50fc28f5be6aa0a9af5f0562f0
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    kevinsawicki committed Apr 8, 2011
    Copy the full SHA
    8920427 View commit details
  2. Add a proper branding icon

    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    caniszczyk committed Apr 8, 2011
    Copy the full SHA
    03f2f6c View commit details
  3. ClassCastException when creating a gist via editor text selection

    A TextSelection is casted to a IStructuredException in CreateGistHandler.
    
    Bug: 342337
    Change-Id: I05f5824617b0a6dfc5a03a4c530aeeaebd641876
    Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
    smilebase committed Apr 8, 2011
    Copy the full SHA
    9769090 View commit details

Commits on Apr 9, 2011

  1. Update to use Tycho 0.11

    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    caniszczyk committed Apr 9, 2011
    Copy the full SHA
    386e70b View commit details

Commits on Apr 10, 2011

  1. Add user and request error model support

    Change-Id: Ic2ddda0eada498ebbabb9aefdd741ce5bd595c34
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    dec33a8 View commit details
  2. Add comment and milestone model support

    Change-Id: If336ef2527a58d89d83cd8949370005768e53b89
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    ca6bf18 View commit details
  3. Add support for displaying an issue's labels

    Change-Id: I97b56c9fbd4f6c0962a0275c451554786e13e03b
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    ccaf4c9 View commit details
  4. Add interface for new API constants

    Change-Id: I6d6a7c4265921a1cccd5dc5d979824923272c38a
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    d1db183 View commit details
  5. Add GitHub client class for new API

    Change-Id: I8f4681353bcfcffc7efbc9bb4f726dc61a45a563
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    9907904 View commit details
  6. Add label and issue model classes for new API

    Change-Id: I035aa1dd7e64354bc2cc07c1da9f36a73016c9f5
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    3301f6a View commit details
  7. Add support for getting an issue using new API

    Change-Id: I6211b9da6faa44a0185a6fa6cb187e81985adda7
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    1852237 View commit details
  8. Add support for getting an issue's comments

    Change-Id: I7709adc3d71ab5e0cf533f44a9a35f1db1f04b62
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    bd1c7a9 View commit details
  9. Add support for getting a list of issues matching filters

    Added constants for allowable filter keys and values.
    
    Change-Id: Ie175af2cc7b47afdf3e89f0f413e371306e0653d
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    f3ab380 View commit details
  10. Add support for creating issues using JSON POST request

    Change-Id: Ifc25874f66fe153f8629e2375ff476b2a35aabb8
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 10, 2011
    Copy the full SHA
    052abaf View commit details
  11. Not null unit tests for IssueService#getIssue

    Change-Id: I1e22682fa36f81ec25ccb9aabf872a4c010ce520
    Signed-off-by: Christian Trutz <christian.trutz@gmail.com>
    smilebase committed Apr 10, 2011
    Copy the full SHA
    faa3199 View commit details

Commits on Apr 11, 2011

  1. Add task attributes for assignee and milestone fields

    Change-Id: Ifd186b1087a2b9e67d1c11a252ed6574f0cce97e
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 11, 2011
    Copy the full SHA
    c093f6e View commit details
  2. Add support for getting labels used in a repository

    This will be used in the query dialog to search for
    issues that match all selected labels.
    
    Change-Id: I9726556cc3ad5a7432997e63ce3da14ac1ac0a03
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 11, 2011
    Copy the full SHA
    ad7ca72 View commit details
  3. Add support for getting milestones used in a repository

    This will be used in the query dialog to search for
    issues that are in a selected milestone.
    
    Change-Id: I54d1e490c554a26bdd7cef9a1b458d00bca443ca
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 11, 2011
    Copy the full SHA
    c52d054 View commit details
  4. Remove API token support which is not supported in v3

    GitHub password now required for issue task repository
    which is supported in both v2 and v3 APIs.
    
    Change-Id: I36dac5b68d7476843b9b19351d41ad21d718e927
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 11, 2011
    Copy the full SHA
    e9fe868 View commit details
  5. Merge "Remove API token support which is not supported in v3"

    caniszczyk authored and Code Review committed Apr 11, 2011
    Copy the full SHA
    22fe54e View commit details

Commits on Apr 12, 2011

  1. Migrate task data handler and attribute mapper to use new API

    Change-Id: I13f6d9928e16b70d46bff3cb3313edfc0fdf92d2
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    0c4b3ac View commit details
  2. Add caching and refreshing of labels and milestones

    This will be used in the task editor and query page to
    display current milestones and labels.
    
    Change-Id: I1f83ceabc288e866ae97e4a66d9d2aeb47691e6b
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    c37f280 View commit details
  3. Add issue label comparator used for sorting in lists

    Change-Id: Idb584baad24d10ae6c4ca527c9bb9748a75c7532
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    e7ee811 View commit details
  4. Add utility for storing values in a repository query attribute

    Change-Id: Iae11bb46d4f04b5ae96aead7168aec4b7ad5a56d
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    dc79215 View commit details
  5. Add support for querying issues using new API parameters

    Supports queries on labels, milestone, mentions,
    assignee, and state.
    
    Change-Id: I0fadec754ab5143e5d3087eebb0cca78bc7ca672
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    d241156 View commit details
  6. Migrate query page to support new filter parameters

    Change-Id: I0d9645e5030b9ab909d869b5c3b9a53b46fc3bc1
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    4c78b55 View commit details
  7. Add task attributes for assignee/reporter gravatar url

    Change-Id: Idc8804c665b9bed938116b93a204e40a3f8fc54d
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    7fcde31 View commit details
  8. Add class to fetch and cache avatar image data

    Change-Id: Ifaf6611f554deeef538c6b9dc7890021df0e8c26
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    80a1f56 View commit details
  9. Add avatar label widget to be used in task editor

    Change-Id: I892d30cf0e8e013bfdbf4940eefc5be4d69da696
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    d62e2e4 View commit details
  10. Add avatar store field to UI plug-in instance

    This store loads and saves when the bundle starts
    and stops.
    
    Change-Id: I26cf039cca00f9ff8a93591d4e09c061de38bf5e
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    74244ef View commit details
  11. Add custom summary task editor part to display avatars

    Change-Id: I13b19b9b65031bf295a6adf9e946e958681a716c
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    039d7d6 View commit details
  12. Use custom summary part from issue task editor page

    Change-Id: I76e460864b6132fb18c3e4d0567b46c67e7f5a33
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    c3a4fc1 View commit details
  13. Clean up image usage and a label

    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    caniszczyk committed Apr 12, 2011
    Copy the full SHA
    c22f60e View commit details
  14. Merge "Clean up image usage and a label"

    caniszczyk authored and Code Review committed Apr 12, 2011
    Copy the full SHA
    f08f1fe View commit details
  15. Merge "Not null unit tests for IssueService#getIssue"

    caniszczyk authored and Code Review committed Apr 12, 2011
    Copy the full SHA
    3100a86 View commit details
  16. Add icon for issue labels for query dialog and task editor

    Change-Id: I82e583d3551e0067d881a89defa8ee0443e7fcf9
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    5f60a4f View commit details
  17. Add PUT request support to GitHubClient

    This will be used to update existing issues.
    
    Change-Id: I056b72934056daf8dbe7bdf4d38a9ec13dce106e
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    42903ba View commit details
  18. Add support for creating comments and issues using new API

    Change-Id: If51002c9bd11505453d5d2cdfeca708f37ac1568
    Signed-off-by: Kevin Sawicki <kevin@github.com>
    Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
    kevinsawicki authored and caniszczyk committed Apr 12, 2011
    Copy the full SHA
    2598308 View commit details
Showing 450 changed files with 49,946 additions and 2,783 deletions.
12 changes: 12 additions & 0 deletions .eclipse_iplog
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project "technology.egit"]
name = EGit
license = Eclipse Public License v1.0

[review]
url = http://egit.eclipse.org/r/r/

[consumes "technology.jgit"]
name = JGit
version = 1.3.0
license = Eclipse Distribution License v1.0

44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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 :).
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/
7 changes: 7 additions & 0 deletions org.eclipse.egit.github.core.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions org.eclipse.egit.github.core.tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
target
28 changes: 28 additions & 0 deletions org.eclipse.egit.github.core.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.egit.github.core.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Wed May 18 07:04:44 CEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#Wed Sep 07 17:28:01 PDT 2011
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
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_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.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_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_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=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
21 changes: 21 additions & 0 deletions org.eclipse.egit.github.core.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.egit.github.core.tests
Bundle-Version: 4.1.0.qualifier
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
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="[4.1.0,4.2.0)",
org.eclipse.egit.github.core.client;version="[4.1.0,4.2.0)",
org.eclipse.egit.github.core.event;version="[4.1.0,4.2.0)",
org.eclipse.egit.github.core.service;version="[4.1.0,4.2.0)",
org.eclipse.egit.github.core.util;version="[4.1.0,4.2.0)",
org.mockito;version="[1.8.4,2.0.0)",
org.mockito.runners;version="[1.8.4,2.0.0)",
org.mockito.stubbing;version="[1.8.4,2.0.0)"
Require-Bundle: org.junit;bundle-version="[4.8.1,5.0.0)",
org.hamcrest;bundle-version="[1.1.0,2.0.0)",
org.objenesis;bundle-version="[1.0.0,2.0.0)"
Bundle-Vendor: %providerName
5 changes: 5 additions & 0 deletions org.eclipse.egit.github.core.tests/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties
2 changes: 2 additions & 0 deletions org.eclipse.egit.github.core.tests/plugin.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pluginName=EGit GitHub API Tests
providerName=Eclipse EGit
46 changes: 46 additions & 0 deletions org.eclipse.egit.github.core.tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com>
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.mylyn.github</groupId>
<artifactId>github-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.egit.github.core.tests</artifactId>
<packaging>eclipse-test-plugin</packaging>

<name>Eclipse EGit GitHub API Test Plug-in</name>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<excludes>
<!-- test mojo matches TestProject be default and treats it as PojoTest -->
<exclude>**/Test*.class</exclude>
</excludes>
<useUIHarness>false</useUIHarness>
<useUIThread>false</useUIThread>
<testSuite>org.eclipse.egit.github.core.tests</testSuite>
<testClass>org.eclipse.egit.github.core.tests.AllHeadlessTests</testClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Green <david.green@tasktop.com> - initial contribution
* Christian Trutz <christian.trutz@gmail.com> - initial contribution
* Chris Aniszczyk <caniszczyk@gmail.com> - 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, //
CommitCommentTest.class, //
CommitFileTest.class, //
CommitServiceTest.class, //
CommitStatsTest.class, //
CommitStatusTest.class, //
CommitTest.class, //
CommitUserTest.class, //
ContentsServiceTest.class, //
ContributorTest.class, //
DataServiceTest.class, //
DateFormatterTest.class, //
DateUtilTests.class, //
DeployKeyServiceTest.class, //
DownloadServiceTest.class, //
DownloadTest.class, //
DownloadResourceTest.class, //
EncodingUtilsTest.class, //
EventFormatterTest.class, //
EventPayloadTest.class, //
EventRepositoryTest.class, //
EventServiceTest.class, //
EventTest.class, //
FieldErrorTest.class, //
GistChangeStatusTest.class, //
GistFileTest.class, //
GistRevisionTest.class, //
GistServiceTest.class, //
GistTest.class, //
GitHubClientTest.class, //
GollumPageTest.class, //
GsonUtilsTest.class, //
IdTest.class, //
IssueEventTest.class, //
IssueServiceTest.class, //
IssueTest.class, //
KeyTest.class, //
LabelComparatorTest.class, //
LabelServiceTest.class, //
LabelTest.class, //
LanguageTest.class, //
MarkdownServiceTest.class, //
MergeStatusTest.class, //
MilestoneComparatorTest.class, //
MilestoneServiceTest.class, //
MilestoneTest.class, //
OAuthServiceTest.class, //
OrganizationServiceTest.class, //
PagedRequestTest.class, //
PullRequestMarkerTest.class, //
PullRequestServiceTest.class, //
PullRequestTest.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, //
TagTest.class, //
TeamServiceTest.class, //
TeamTest.class, //
TreeEntryTest.class, //
TreeTest.class, //
TypedResourceTest.class, //
UrlUtilsTest.class, //
UserPlanTest.class, //
UserServiceTest.class, //
UserTest.class, //
WatcherServiceTest.class //
})
public class AllHeadlessTests {

}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.runners.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, "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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("<body>", comment.setBodyHtml("<body>").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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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>(),
commit.setParents(new ArrayList<Commit>()).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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.runners.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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 DateUtilTests {

/**
* 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));
}

}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.runners.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");
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.runners.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}

}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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(new String(encoded));
assertNotNull(decoded);
assertFalse(decoded.length == 0);
assertEquals(test, new String(decoded));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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 static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;

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.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.runners.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 {
doReturn(response).when(gitHubClient).get(any(GitHubRequest.class));
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<Event> 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<Event> 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<Event> 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<Event> 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<Event> 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<Event> 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<Event> 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<Event> 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<Event> iterator = eventService.pageUserOrgEvents("user", "org");
assertNotNull(iterator);
assertTrue(iterator.hasNext());
assertEquals(Utils.page("/users/user/events/orgs/org"), iterator
.getRequest().generateUri());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.getUser());
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.<String, GistFile> emptyMap())
.getFiles());
assertEquals("pull", gist.setGitPullUrl("pull").getGitPullUrl());
assertEquals("push", gist.setGitPushUrl("push").getGitPushUrl());
assertEquals(Collections.emptyList(),
gist.setHistory(Collections.<GistRevision> 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.setUser(user).getUser());
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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"));
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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<GollumPage> pages = new ArrayList<GollumPage>();
pages.add(new GollumPage().setPageName("page"));
assertEquals(pages, payload.setPages(pages).getPages());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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()));
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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("<body>", issue.setBodyHtml("<body>").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<Label>(),
issue.setLabels(new ArrayList<Label>()).getLabels());
Milestone milestone = new Milestone().setNumber(50);
assertEquals(milestone, issue.setMilestone(milestone).getMilestone());
assertEquals(123, issue.setNumber(123).getNumber());
PullRequest pr = new PullRequest().setNumber(500);
assertEquals(pr, issue.setPullRequest(pr).getPullRequest());
assertEquals("state", issue.setState("state").getState());
assertEquals("title", issue.setTitle("title").getTitle());
assertEquals(new Date(3000), issue.setUpdatedAt(new Date(3000))
.getUpdatedAt());
assertEquals("url", issue.setUrl("url").getUrl());
User user = new User().setLogin("user");
assertEquals(user, issue.setUser(user).getUser());
assertNull(issue.setLabels(null).getLabels());
assertEquals(39, issue.setId(39).getId());
assertEquals("user", issue.setClosedBy(user).getClosedBy().getLogin());
}

/**
* Test non-mutable created at date
*/
@Test
public void getCreatedAtReferenceMutableObject() {
Issue issue = new Issue();
issue.setCreatedAt(new Date(55555555));
issue.getCreatedAt().setTime(0);
assertTrue(issue.getCreatedAt().getTime() != 0);
}

/**
* Test non-mutable updated at date
*/
@Test
public void getUpdatedAtReferenceMutableObject() {
Issue issue = new Issue();
issue.setUpdatedAt(new Date(44444444));
issue.getUpdatedAt().setTime(0);
assertTrue(issue.getUpdatedAt().getTime() != 0);
}

/**
* Test non-mutable closed at date
*/
@Test
public void getClosedAtReferenceMutableObject() {
Issue issue = new Issue();
issue.setClosedAt(new Date(99999999));
issue.getClosedAt().setTime(0);
assertTrue(issue.getClosedAt().getTime() != 0);
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Issue;
import org.eclipse.egit.github.core.event.IssuesPayload;
import org.junit.Test;

/**
* Unit tests of {@link IssuesPayload}
*/
public class IssuesPayloadTest {

/**
* Test default state of IssuesPayload
*/
@Test
public void defaultState() {
IssuesPayload payload = new IssuesPayload();
assertNull(payload.getAction());
assertNull(payload.getIssue());
}

/**
* Test updating IssuesPayload fields
*/
@Test
public void updateFields() {
IssuesPayload payload = new IssuesPayload();
Issue issue = new Issue().setTitle("issue");
assertEquals("create", payload.setAction("create").getAction());
assertEquals(issue, payload.setIssue(issue).getIssue());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Key;
import org.junit.Test;

/**
* Unit tests of {@link Key}
*/
public class KeyTest {

/**
* Test default state of key
*/
@Test
public void defaultState() {
Key key = new Key();
assertEquals(0, key.getId());
assertNull(key.getKey());
assertNull(key.getTitle());
assertNull(key.getUrl());
}

/**
* Test updating key fields
*/
@Test
public void updateFields() {
Key key = new Key();
assertEquals(75, key.setId(75).getId());
assertEquals("a key", key.setKey("a key").getKey());
assertEquals("b title", key.setTitle("b title").getTitle());
assertEquals("/a/b", key.setUrl("/a/b").getUrl());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Label;
import org.eclipse.egit.github.core.util.LabelComparator;
import org.junit.Test;

/**
* Unit tests of {@link LabelComparator}
*/
public class LabelComparatorTest {

/**
* Compare labels
*/
@Test
public void compareLabels() {
LabelComparator cmp = new LabelComparator();
Label l1 = new Label().setName("a");
Label l2 = new Label().setName("b");
assertEquals(-1, cmp.compare(l1, l2));
assertEquals(0, cmp.compare(l1, l1));
assertEquals(1, cmp.compare(l2, l1));
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.assertNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.egit.github.core.Label;
import org.junit.Test;

/**
* Unit tests of {@link Label}
*/
public class LabelTest {

/**
* Test label default state
*/
@Test
public void defaultState() {
Label label = new Label();
assertNull(label.getColor());
assertNull(label.getName());
assertNull(label.getUrl());
}

/**
* Test updating label fields
*/
@Test
public void updateFields() {
Label label = new Label();
assertEquals("red", label.setColor("red").getColor());
assertEquals("bug", label.setName("bug").getName());
assertEquals("url", label.setUrl("url").getUrl());
}

/**
* Test equality of labels
*/
@Test
public void equality() {
Label l1 = new Label();
assertEquals(l1.hashCode(), l1.hashCode());
assertNotNull(l1.toString());
Label l2 = new Label().setName("b");
assertFalse(l1.equals(l2));
l1.setName("a");
Label l3 = new Label().setName("a");
assertTrue(l1.equals(l1));
assertFalse(l1.equals("a"));
assertFalse(l1.equals(l2));
assertTrue(l1.equals(l3));
assertEquals(l1.hashCode(), l3.hashCode());
assertEquals(l1.toString(), l3.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
*****************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.egit.github.core.Language;
import org.junit.Test;

/**
* Unit tests of {@link Language}
*/
public class LanguageTest {

/**
* Test languages
*/
@Test
public void languages() {
assertNotNull(Language.values());
assertTrue(Language.values().length > 0);
for (Language lang : Language.values()) {
assertNotNull(lang);
assertNotNull(Language.valueOf(lang.name()));
assertNotNull(lang.getValue());
assertFalse(lang.getValue().length() == 0);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
*****************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.eclipse.egit.github.core.client.IGitHubConstants.CHARSET_UTF8;
import static org.eclipse.egit.github.core.service.MarkdownService.MODE_MARKDOWN;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;

import java.io.ByteArrayInputStream;
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.service.MarkdownService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

/**
* Unit tests of {@link MarkdownService}
*/
@RunWith(MockitoJUnitRunner.class)
public class MarkdownServiceTest {

@Mock
private GitHubClient client;

private MarkdownService service;

private RepositoryId repo;

private String content;

/**
* Test case set up
*
* @throws IOException
*/
@Before
public void before() throws IOException {
content = "<p>content</p>";
ByteArrayInputStream stream = new ByteArrayInputStream(
content.getBytes(CHARSET_UTF8));
doReturn(stream).when(client).postStream(any(String.class),
any(Object.class));
service = new MarkdownService(client);
repo = new RepositoryId("o", "n");
}

/**
* Get repository HTML
*
* @throws Exception
*/
@Test
public void getRepositoryHtml() throws Exception {
assertEquals(content, service.getRepositoryHtml(repo, "input"));
}

/**
* Get repository HTML
*
* @throws Exception
*/
@Test(expected = IllegalArgumentException.class)
public void getRepositoryHtmlNullRepository() throws Exception {
service.getRepositoryHtml(null, "input");
}

/**
* Get HTML
*
* @throws Exception
*/
@Test
public void getHtml() throws Exception {
assertEquals(content, service.getHtml("input", MODE_MARKDOWN));
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.MemberPayload;
import org.junit.Test;

/**
* Unit tests of {@link MemberPayload}
*/
public class MemberPayloadTest {

/**
* Test default state of MemberPayload
*/
@Test
public void defaultState() {
MemberPayload payload = new MemberPayload();
assertNull(payload.getMember());
assertNull(payload.getAction());
}

/**
* Test updating MemberPayload fields
*/
@Test
public void updateFields() {
MemberPayload payload = new MemberPayload();
User member = new User().setLogin("member");
assertEquals(member, payload.setMember(member).getMember());
assertEquals("create", payload.setAction("create").getAction());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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 org.eclipse.egit.github.core.MergeStatus;
import org.junit.Test;

/**
* Unit tests of {@link MergeStatus}
*/
public class MergeStatusTest {

/**
* Test default status of merge status
*/
@Test
public void defaultState() {
MergeStatus status = new MergeStatus();
assertFalse(status.isMerged());
assertNull(status.getMessage());
assertNull(status.getSha());
}

/**
* Test updating merge status fields
*/
@Test
public void updateFields() {
MergeStatus status = new MergeStatus();
assertTrue(status.setMerged(true).isMerged());
assertEquals("message", status.setMessage("message").getMessage());
assertEquals("aabbcc", status.setSha("aabbcc").getSha());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Milestone;
import org.eclipse.egit.github.core.util.MilestoneComparator;
import org.junit.Test;

/**
* Unit tests of {@link MilestoneComparator}
*/
public class MilestoneComparatorTest {

/**
* Compare milestones
*/
@Test
public void compareMilestones() {
MilestoneComparator cmp = new MilestoneComparator();
Milestone m1 = new Milestone().setTitle("a");
Milestone m2 = new Milestone().setTitle("b");
assertEquals(-1, cmp.compare(m1, m2));
assertEquals(0, cmp.compare(m1, m1));
assertEquals(1, cmp.compare(m2, m1));
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Milestone;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

/**
* Unit tests of {@link Milestone}
*/
public class MilestoneTest {

/**
* Test default state of milestone
*/
@Test
public void defaultState() {
Milestone milestone = new Milestone();
assertEquals(0, milestone.getClosedIssues());
assertNull(milestone.getCreatedAt());
assertNull(milestone.getCreator());
assertNull(milestone.getDescription());
assertNull(milestone.getDueOn());
assertEquals(0, milestone.getNumber());
assertEquals(0, milestone.getOpenIssues());
assertNull(milestone.getState());
assertNull(milestone.getTitle());
assertNull(milestone.getUrl());
}

/**
* Test updating milestone fields
*/
@Test
public void updateFields() {
Milestone milestone = new Milestone();
assertEquals(1, milestone.setClosedIssues(1).getClosedIssues());
assertEquals(new Date(10000), milestone.setCreatedAt(new Date(10000))
.getCreatedAt());
User creator = new User().setLogin("creator");
assertEquals(creator, milestone.setCreator(creator).getCreator());
assertEquals("desc", milestone.setDescription("desc").getDescription());
assertEquals(new Date(20000), milestone.setDueOn(new Date(20000))
.getDueOn());
assertEquals(4, milestone.setNumber(4).getNumber());
assertEquals(10, milestone.setOpenIssues(10).getOpenIssues());
assertEquals("state", milestone.setState("state").getState());
assertEquals("title", milestone.setTitle("title").getTitle());
assertEquals("url", milestone.setUrl("url").getUrl());
}

/**
* Test non-mutable created at date
*/
@Test
public void getCreatedAtReferenceMutableObject() {
Milestone milestone = new Milestone();
milestone.setCreatedAt(new Date(5000));
milestone.getCreatedAt().setTime(0);
assertTrue(milestone.getCreatedAt().getTime() != 0);
}

/**
* Test non-mutable due on date
*/
@Test
public void getDueOn_ReferenceMutableObject() {
Milestone milestone = new Milestone();
milestone.setDueOn(new Date(2000));
milestone.getDueOn().setTime(0);
assertTrue(milestone.getDueOn().getTime() != 0);
}

/**
* Test non-mutable due on date
*/
@Test
public void setDueOnReferenceMutableObject() {
Milestone milestone = new Milestone();
Date longTimeAgo = new Date(0L);
milestone.setDueOn(longTimeAgo);
longTimeAgo.setTime(10000L);
assertTrue(milestone.getDueOn().getTime() == 0L);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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 java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.eclipse.egit.github.core.Authorization;
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.OAuthService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

/**
* Unit tests of {@link OAuthService}
*/
@RunWith(MockitoJUnitRunner.class)
public class OAuthServiceTest {

@Mock
private GitHubClient client;

@Mock
private GitHubResponse response;

private OAuthService service;

/**
* Test case set up
*
* @throws IOException
*/
@Before
public void before() throws IOException {
doReturn(response).when(client).get(any(GitHubRequest.class));
service = new OAuthService(client);
}

/**
* Create service with null client
*/
@Test(expected = IllegalArgumentException.class)
public void constructorNullArgument() {
new OAuthService(null);
}

/**
* Create service using default constructor
*/
@Test
public void defaultConstructor() {
assertNotNull(new OAuthService().getClient());
}

/**
* Get authorizations
*
* @throws IOException
*/
@Test
public void getAuthorizations() throws IOException {
service.getAuthorizations();
GitHubRequest request = new GitHubRequest();
request.setUri(Utils.page("/authorizations"));
verify(client).get(request);
}

/**
* Get authorization
*
* @throws IOException
*/
@Test
public void getAuthorization() throws IOException {
service.getAuthorization(400);
GitHubRequest request = new GitHubRequest();
request.setUri("/authorizations/400");
verify(client).get(request);
}

/**
* Delete authorization
*
* @throws IOException
*/
@Test
public void deleteAuthorization() throws IOException {
service.deleteAuthorization(678);
verify(client).delete("/authorizations/678");
}

/**
* Create authorization
*
* @throws IOException
*/
@Test
public void createAuthorization() throws IOException {
Authorization auth = new Authorization();
service.createAuthorization(auth);
verify(client).post("/authorizations", auth, Authorization.class);
}

/**
* Test adding scopes to authorization
*
* @throws IOException
*/
@Test
public void addScopes() throws IOException {
Collection<String> scopes = Arrays.asList("repo");
service.addScopes(300, scopes);
verify(client).post("/authorizations/300",
Collections.singletonMap("add_scopes", scopes),
Authorization.class);
}

/**
* Test removing scopes to authorization
*
* @throws IOException
*/
@Test
public void removeScopes() throws IOException {
Collection<String> scopes = Arrays.asList("user");
service.removeScopes(400, scopes);
verify(client).post("/authorizations/400",
Collections.singletonMap("remove_scopes", scopes),
Authorization.class);
}

/**
* Test setting scopes to authorization
*
* @throws IOException
*/
@Test
public void setScopes() throws IOException {
Collection<String> scopes = Arrays.asList("gist");
service.setScopes(500, scopes);
verify(client)
.post("/authorizations/500",
Collections.singletonMap("scopes", scopes),
Authorization.class);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
*****************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.junit.Assert.assertTrue;

import org.eclipse.egit.github.core.client.PagedRequest;
import org.junit.Test;

/**
* Unit tests of {@link PagedRequest}
*/
public class PagedRequestTest {

/**
* Test default state of paged request
*/
@Test
public void defaultState() {
PagedRequest<String> request = new PagedRequest<String>();
assertTrue(request.getPage() > 0);
assertTrue(request.getPageSize() > 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.PullRequestMarker;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

/**
* Unit tests of {@link PullRequestMarker}
*/
public class PullRequestMarkerTest {

/**
* Test default state of pull request marker
*/
@Test
public void defaultState() {
PullRequestMarker marker = new PullRequestMarker();
assertNull(marker.getLabel());
assertNull(marker.getRef());
assertNull(marker.getRepo());
assertNull(marker.getSha());
assertNull(marker.getUser());
}

/**
* Test updating pull request marker fields
*/
@Test
public void updateFields() {
PullRequestMarker marker = new PullRequestMarker();
assertEquals("lab1", marker.setLabel("lab1").getLabel());
assertEquals("master", marker.setRef("master").getRef());
Repository repo = new Repository().setName("trepo");
assertEquals(repo, marker.setRepo(repo).getRepo());
assertEquals("000", marker.setSha("000").getSha());
User user = new User().setLogin("tuser");
assertEquals(user, marker.setUser(user).getUser());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.PullRequest;
import org.eclipse.egit.github.core.event.PullRequestPayload;
import org.junit.Test;

/**
* Unit tests of {@link PullRequestPayload}
*/
public class PullRequestPayloadTest {

/**
* Test default state of PullRequestPayload
*/
@Test
public void defaultState() {
PullRequestPayload payload = new PullRequestPayload();
assertNull(payload.getAction());
assertEquals(0, payload.getNumber());
assertNull(payload.getPullRequest());
}

/**
* Test updating PullRequestPayload fields
*/
@Test
public void updateFields() {
PullRequestPayload payload = new PullRequestPayload();
PullRequest pullRequest = new PullRequest().setTitle("pull");
assertEquals("create", payload.setAction("create").getAction());
assertEquals(9000, payload.setNumber(9000).getNumber());
assertEquals(pullRequest, payload.setPullRequest(pullRequest).getPullRequest());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.CommitComment;
import org.eclipse.egit.github.core.event.PullRequestReviewCommentPayload;
import org.junit.Test;

/**
* Unit tests of {@link PullRequestReviewCommentPayload}
*/
public class PullRequestReviewCommentPayloadTest {

/**
* Test default state of {@link PullRequestReviewCommentPayload}
*/
@Test
public void defaultState() {
PullRequestReviewCommentPayload payload = new PullRequestReviewCommentPayload();
assertNull(payload.getComment());
}

/**
* Test updating {@link PullRequestReviewCommentPayload} fields
*/
@Test
public void updateFields() {
PullRequestReviewCommentPayload payload = new PullRequestReviewCommentPayload();
CommitComment comment = new CommitComment();
assertEquals(comment, payload.setComment(comment).getComment());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christian Trutz - 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.Matchers.notNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import java.io.IOException;

import org.eclipse.egit.github.core.CommitComment;
import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.MergeStatus;
import org.eclipse.egit.github.core.PullRequest;
import org.eclipse.egit.github.core.PullRequestMarker;
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.PullRequestService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

/**
* Unit tests of {@link PullRequestService}
*/
@RunWith(MockitoJUnitRunner.class)
public class PullRequestServiceTest {

@Mock
private GitHubClient gitHubClient;

@Mock
private GitHubResponse response;

private RepositoryId repo;

private PullRequestService pullRequestService;

/**
* Test case set up
*
* @throws IOException
*/
@Before
public void before() throws IOException {
pullRequestService = new PullRequestService(gitHubClient);
doReturn(response).when(gitHubClient).get(any(GitHubRequest.class));
repo = new RepositoryId("o", "n");
}

/**
* Create service using default constructor
*/
@Test
public void constructor() {
assertNotNull(new PullRequestService().getClient());
}

/**
* Create pull request service with null client
*/
@Test(expected = IllegalArgumentException.class)
public void constructorNullArgument() {
new PullRequestService(null);
}

/**
* Get pull request with null repository
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void getPullRequestNullRepository() throws IOException {
pullRequestService.getPullRequest(null, 3);
}

/**
* Get pull request
*
* @throws IOException
*/
@Test
public void getPullRequest() throws IOException {
pullRequestService.getPullRequest(repo, 5);
GitHubRequest request = new GitHubRequest();
request.setUri("/repos/o/n/pulls/5");
verify(gitHubClient).get(request);
}

/**
* Get pull requests with null repository
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void getPullRequestsNullRepository() throws IOException {
pullRequestService.getPullRequests(null, "not null");
}

/**
* Get pull request with repository that generates a null id
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void getPullRequestsNullRepositoryId() throws IOException {
pullRequestService.getPullRequests(new IRepositoryIdProvider() {

public String generateId() {
return null;
}
}, "test_state");
}

/**
* Get pull requests
*
* @throws IOException
*/
@Test
public void getPullRequests() throws IOException {
pullRequestService.getPullRequests(repo, "open");
GitHubRequest request = new GitHubRequest();
request.setUri(Utils.page("/repos/o/n/pulls?state=open"));
verify(gitHubClient).get(request);
}

/**
* Get pull request comment
*
* @throws IOException
*/
@Test
public void getComment() throws IOException {
pullRequestService.getComment(repo, 65);
GitHubRequest request = new GitHubRequest();
request.setUri("/repos/o/n/pulls/comments/65");
verify(gitHubClient).get(request);
}

/**
* Get pull request comment
*
* @throws IOException
*/
@Test
public void getComments() throws IOException {
pullRequestService.getComments(repo, 6);
GitHubRequest request = new GitHubRequest();
request.setUri(Utils.page("/repos/o/n/pulls/6/comments"));
verify(gitHubClient).get(request);
}

/**
* Get pull request files
*
* @throws IOException
*/
@Test
public void getFiles() throws IOException {
pullRequestService.getFiles(repo, 5);
GitHubRequest request = new GitHubRequest();
request.setUri(Utils.page("/repos/o/n/pulls/5/files"));
verify(gitHubClient).get(request);
}

/**
* Get pull request commits
*
* @throws IOException
*/
@Test
public void getCommits() throws IOException {
pullRequestService.getCommits(repo, 5);
GitHubRequest request = new GitHubRequest();
request.setUri(Utils.page("/repos/o/n/pulls/5/commits"));
verify(gitHubClient).get(request);
}

/**
* Is merged
*
* @throws IOException
*/
@Test
public void isMerged() throws IOException {
pullRequestService.isMerged(repo, 8);
GitHubRequest request = new GitHubRequest();
request.setUri("/repos/o/n/pulls/8/merge");
verify(gitHubClient).get(request);
}

/**
* Merge pull request
*
* @throws IOException
*/
@Test
public void merge() throws IOException {
pullRequestService.merge(repo, 8, "merge");
verify(gitHubClient).put(eq("/repos/o/n/pulls/8/merge"), any(),
eq(MergeStatus.class));
}

/**
* Create pull request comment
*
* @throws IOException
*/
@Test
public void createComment() throws IOException {
CommitComment comment = new CommitComment();
comment.setBody("looks good");
pullRequestService.createComment(repo, 3, comment);
verify(gitHubClient).post("/repos/o/n/pulls/3/comments", comment,
CommitComment.class);
}

/**
* Reply to pull request comment
*
* @throws IOException
*/
@Test
public void replyToComment() throws IOException {
pullRequestService.replyToComment(repo, 5, 10, "reply");
verify(gitHubClient).post(eq("/repos/o/n/pulls/5/comments"), notNull(),
eq(CommitComment.class));
}

/**
* Create pull request
*
* @throws IOException
*/
@Test
public void createPullRequest() throws IOException {
PullRequest request = new PullRequest();
request.setBody("a fix");
request.setTitle("this is a fix");
request.setHead(new PullRequestMarker().setRef("master"));
request.setBase(new PullRequestMarker().setRef("b1"));
pullRequestService.createPullRequest(repo, request);
verify(gitHubClient).post(eq("/repos/o/n/pulls"), notNull(),
eq(PullRequest.class));
}

/**
* Create pull request from issue
*
* @throws IOException
*/
@Test
public void createPullRequestFromIssue() throws IOException {
pullRequestService.createPullRequest(repo, 49, "master", "v1");
verify(gitHubClient).post(eq("/repos/o/n/pulls"), notNull(),
eq(PullRequest.class));
}

/**
* Edit pull request with null request
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void editPullRequestNullRequest() throws IOException {
pullRequestService.editPullRequest(repo, null);
}

/**
* Edit pull request
*
* @throws IOException
*/
@Test
public void editPullRequest() throws IOException {
PullRequest request = new PullRequest().setNumber(33);
request.setBody("a body");
request.setTitle("new title");
request.setState("merged");
pullRequestService.editPullRequest(repo, request);
verify(gitHubClient).post(eq("/repos/o/n/pulls/33"), notNull(),
eq(PullRequest.class));
}

/**
* Delete pull request comment
*
* @throws IOException
*/
@Test
public void deleteComment() throws IOException {
pullRequestService.deleteComment(repo, 589);
verify(gitHubClient).delete("/repos/o/n/pulls/comments/589");
}

/**
* Edit comment with null comment
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void editCommentNullComment() throws IOException {
pullRequestService.editComment(repo, null);
}

/**
* Edit comment
*
* @throws IOException
*/
@Test
public void editComment() throws IOException {
CommitComment comment = new CommitComment();
comment.setId(78).setBody("a newer body");
pullRequestService.editComment(repo, comment);
verify(gitHubClient).post("/repos/o/n/pulls/comments/78", comment,
CommitComment.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Date;

import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.PullRequest;
import org.eclipse.egit.github.core.PullRequestMarker;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

/**
* Unit tests of {@link PullRequest}
*/
public class PullRequestTest {

/**
* Test default state of pull request
*/
@Test
public void defaultState() {
PullRequest request = new PullRequest();
assertFalse(request.isMergeable());
assertFalse(request.isMerged());
assertEquals(0, request.getAdditions());
assertNull(request.getBase());
assertNull(request.getBody());
assertNull(request.getBodyHtml());
assertNull(request.getBodyText());
assertEquals(0, request.getChangedFiles());
assertNull(request.getClosedAt());
assertEquals(0, request.getComments());
assertEquals(0, request.getReviewComments());
assertEquals(0, request.getCommits());
assertNull(request.getCreatedAt());
assertEquals(0, request.getDeletions());
assertNull(request.getDiffUrl());
assertNull(request.getHead());
assertNull(request.getHtmlUrl());
assertNull(request.getIssueUrl());
assertNull(request.getMergedAt());
assertNull(request.getMergedBy());
assertEquals(0, request.getNumber());
assertNull(request.getPatchUrl());
assertNull(request.getState());
assertNull(request.getTitle());
assertNull(request.getUpdatedAt());
assertNull(request.getUrl());
assertNull(request.getUser());
assertNotNull(request.toString());
assertEquals(0, request.getId());
assertNull(request.getMilestone());
assertNull(request.getAssignee());
}

/**
* Test updating pull request fields
*/
@Test
public void updateFields() {
PullRequest request = new PullRequest();
assertTrue(request.setMerged(true).isMerged());
assertTrue(request.setMergeable(true).isMergeable());
assertEquals(15, request.setAdditions(15).getAdditions());
PullRequestMarker base = new PullRequestMarker();
assertEquals(base, request.setBase(base).getBase());
assertEquals("a pr", request.setBody("a pr").getBody());
assertEquals("<body>", request.setBodyHtml("<body>").getBodyHtml());
assertEquals("text", request.setBodyText("text").getBodyText());
assertEquals(20, request.setChangedFiles(20).getChangedFiles());
assertEquals(new Date(1000), request.setClosedAt(new Date(1000))
.getClosedAt());
assertEquals(30, request.setComments(30).getComments());
assertEquals(35, request.setReviewComments(35).getReviewComments());
assertEquals(40, request.setCommits(40).getCommits());
assertEquals(new Date(2000), request.setCreatedAt(new Date(2000))
.getCreatedAt());
assertEquals(50, request.setDeletions(50).getDeletions());
assertEquals("/diff/url", request.setDiffUrl("/diff/url").getDiffUrl());
PullRequestMarker head = new PullRequestMarker();
assertEquals(head, request.setHead(head).getHead());
assertEquals("/html/url", request.setHtmlUrl("/html/url").getHtmlUrl());
assertEquals("/issue/url", request.setIssueUrl("/issue/url")
.getIssueUrl());
assertEquals(new Date(3000), request.setMergedAt(new Date(3000))
.getMergedAt());
User merge = new User().setLogin("merge user");
assertEquals(merge, request.setMergedBy(merge).getMergedBy());
assertEquals(60, request.setNumber(60).getNumber());
assertEquals("/patch/url", request.setPatchUrl("/patch/url")
.getPatchUrl());
assertEquals("open", request.setState("open").getState());
assertEquals("pull title", request.setTitle("pull title").getTitle());
assertEquals(new Date(4000), request.setUpdatedAt(new Date(4000))
.getUpdatedAt());
assertEquals("/url", request.setUrl("/url").getUrl());
User user = new User().setLogin("cuser");
assertEquals(user, request.setUser(user).getUser());
assertEquals(70, request.setId(70).getId());

User assignee = new User().setLogin("assignee");
assertEquals(assignee, request.setAssignee(assignee).getAssignee());
Milestone milestone = new Milestone().setNumber(456);
assertEquals(milestone, request.setMilestone(milestone).getMilestone());
}

/**
* Test non-mutable created at date
*/
@Test
public void getCreatedAtReferenceMutableObject() {
PullRequest pullRequest = new PullRequest();
pullRequest.setCreatedAt(new Date(10000));
pullRequest.getCreatedAt().setTime(0);
assertTrue(pullRequest.getCreatedAt().getTime() != 0);
}

/**
* Test non-mutable merged at date
*/
@Test
public void getMergedAtReferenceMutableObject() {
PullRequest pullRequest = new PullRequest();
pullRequest.setMergedAt(new Date(20000));
pullRequest.getMergedAt().setTime(0);
assertTrue(pullRequest.getMergedAt().getTime() != 0);
}

/**
* Test non-mutable updated at date
*/
@Test
public void getUpdatedAtReferenceMutableObject() {
PullRequest pullRequest = new PullRequest();
pullRequest.setUpdatedAt(new Date(30000));
pullRequest.getUpdatedAt().setTime(0);
assertTrue(pullRequest.getUpdatedAt().getTime() != 0);
}

/**
* Test non-mutable closed at date
*/
@Test
public void getClosedAtReferenceMutableObject() {
PullRequest pullRequest = new PullRequest();
pullRequest.setClosedAt(new Date(40000));
pullRequest.getClosedAt().setTime(0);
assertTrue(pullRequest.getClosedAt().getTime() != 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Commit;
import org.eclipse.egit.github.core.event.PushPayload;
import org.junit.Test;

/**
* Unit tests of {@link PushPayload}
*/
public class PushPayloadTest {

/**
* Test default state of PushPayload
*/
@Test
public void defaultState() {
PushPayload payload = new PushPayload();
assertNull(payload.getHead());
assertNull(payload.getRef());
assertEquals(0, payload.getSize());
assertNull(payload.getCommits());
assertNull(payload.getBefore());
}

/**
* Test updating PushPayload fields
*/
@Test
public void updateFields() {
PushPayload payload = new PushPayload();
List<Commit> commits = new ArrayList<Commit>();
commits.add(new Commit().setSha("000"));
assertEquals("head", payload.setHead("head").getHead());
assertEquals("ref", payload.setRef("ref").getRef());
assertEquals(9000, payload.setSize(9000).getSize());
assertEquals(commits, payload.setCommits(commits).getCommits());
assertEquals("a1b2", payload.setBefore("a1b2").getBefore());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Reference;
import org.eclipse.egit.github.core.TypedResource;
import org.junit.Test;

/**
* Unit tests of {@link Reference}
*/
public class ReferenceTest {

/**
* Test default state of reference
*/
@Test
public void defaultState() {
Reference ref = new Reference();
assertNull(ref.getObject());
assertNull(ref.getRef());
assertNull(ref.getUrl());
}

/**
* Test updating reference fields
*/
@Test
public void updateFields() {
Reference ref = new Reference();
TypedResource obj = new TypedResource();
obj.setSha("000");
assertEquals(obj, ref.setObject(obj).getObject());
assertEquals("master", ref.setRef("master").getRef());
assertEquals("url://a", ref.setUrl("url://a").getUrl());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.RepositoryBranch;
import org.eclipse.egit.github.core.TypedResource;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryBranch}
*/
public class RepositoryBranchTest {

/**
* Test default state of branch
*/
@Test
public void defaultState() {
RepositoryBranch branch = new RepositoryBranch();
assertNull(branch.getCommit());
assertNull(branch.getName());
}

/**
* Test updating branch fields
*/
@Test
public void updateFields() {
RepositoryBranch branch = new RepositoryBranch();
TypedResource commit = new TypedResource();
commit.setUrl("a").setSha("1");
assertEquals(commit, branch.setCommit(commit).getCommit());
assertEquals("b1", branch.setName("b1").getName());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Arrays;
import java.util.List;

import org.eclipse.egit.github.core.CommitFile;
import org.eclipse.egit.github.core.RepositoryCommit;
import org.eclipse.egit.github.core.RepositoryCommitCompare;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryCommitCompare}
*/
public class RepositoryCommitCompareTest {

/**
* Test default state of repository commit compare
*/
@Test
public void defaultState() {
RepositoryCommitCompare compare = new RepositoryCommitCompare();
assertEquals(0, compare.getAheadBy());
assertNull(compare.getBaseCommit());
assertEquals(0, compare.getBehindBy());
assertNull(compare.getCommits());
assertNull(compare.getDiffUrl());
assertNull(compare.getFiles());
assertNull(compare.getHtmlUrl());
assertNull(compare.getPatchUrl());
assertNull(compare.getPermalinkUrl());
assertNull(compare.getStatus());
assertEquals(0, compare.getTotalCommits());
assertNull(compare.getUrl());
}

/**
* Test updating repository commit compare fields
*/
@Test
public void updateFields() {
RepositoryCommitCompare compare = new RepositoryCommitCompare();
assertEquals(5, compare.setAheadBy(5).getAheadBy());
RepositoryCommit base = new RepositoryCommit();
assertEquals(base, compare.setBaseCommit(base).getBaseCommit());
assertEquals(12, compare.setBehindBy(12).getBehindBy());
List<RepositoryCommit> commits = Arrays.asList(base);
assertEquals(commits, compare.setCommits(commits).getCommits());
assertEquals("diff-url", compare.setDiffUrl("diff-url").getDiffUrl());
List<CommitFile> files = Arrays.asList(new CommitFile());
assertEquals(files, compare.setFiles(files).getFiles());
assertEquals("html-url", compare.setHtmlUrl("html-url").getHtmlUrl());
assertEquals("patch-url", compare.setPatchUrl("patch-url")
.getPatchUrl());
assertEquals("link-url", compare.setPermalinkUrl("link-url")
.getPermalinkUrl());
assertEquals("behind", compare.setStatus("behind").getStatus());
assertEquals(400, compare.setTotalCommits(400).getTotalCommits());
assertEquals("url", compare.setUrl("url").getUrl());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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 java.util.Arrays;
import java.util.List;

import org.eclipse.egit.github.core.Commit;
import org.eclipse.egit.github.core.CommitFile;
import org.eclipse.egit.github.core.CommitStats;
import org.eclipse.egit.github.core.RepositoryCommit;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryCommit}
*/
public class RepositoryCommitTest {

/**
* Test default state of repository commit
*/
@Test
public void defaultState() {
RepositoryCommit commit = new RepositoryCommit();
assertNull(commit.getAuthor());
assertNull(commit.getCommit());
assertNull(commit.getCommitter());
assertNull(commit.getFiles());
assertNull(commit.getParents());
assertNull(commit.getSha());
assertNull(commit.getStats());
assertNull(commit.getUrl());
}

/**
* Test updating repository commit fields
*/
@Test
public void updateFields() {
RepositoryCommit commit = new RepositoryCommit();
User author = new User().setLogin("author");
assertEquals(author, commit.setAuthor(author).getAuthor());
Commit gitCommit = new Commit().setSha("abc");
assertEquals(gitCommit, commit.setCommit(gitCommit).getCommit());
User committer = new User().setLogin("committer");
assertEquals(committer, commit.setCommitter(committer).getCommitter());
assertEquals(new ArrayList<Commit>(),
commit.setParents(new ArrayList<Commit>()).getParents());
assertEquals("0a0", commit.setSha("0a0").getSha());
assertEquals("url", commit.setUrl("url").getUrl());
CommitStats stats = new CommitStats();
assertEquals(stats, commit.setStats(stats).getStats());
List<CommitFile> files = Arrays.asList(new CommitFile()
.setFilename("test.txt"));
assertEquals(files, commit.setFiles(files).getFiles());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.RepositoryContents;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryContents}
*/
public class RepositoryContentsTest {

/**
* Test default state of contents
*/
@Test
public void defaultState() {
RepositoryContents contents = new RepositoryContents();
assertNull(contents.getContent());
assertNull(contents.getEncoding());
assertNull(contents.getName());
assertNull(contents.getPath());
assertNull(contents.getSha());
assertEquals(0, contents.getSize());
assertNull(contents.getType());
}

/**
* Test updating contents fields
*/
@Test
public void updateFields() {
RepositoryContents contents = new RepositoryContents();
assertEquals("abc", contents.setContent("abc").getContent());
assertEquals("64", contents.setEncoding("64").getEncoding());
assertEquals("file.txt", contents.setName("file.txt").getName());
assertEquals("a/b", contents.setPath("a/b").getPath());
assertEquals("abcdef", contents.setSha("abcdef").getSha());
assertEquals(12345, contents.setSize(12345).getSize());
assertEquals("dir", contents.setType("dir").getType());
}
}
Original file line number Diff line number Diff line change
@@ -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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.RepositoryHookResponse;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryHookResponse}
*/
public class RepositoryHookResponseTest {

/**
* Test default state of response
*/
@Test
public void defaultState() {
RepositoryHookResponse response = new RepositoryHookResponse();
assertEquals(0, response.getCode());
assertNull(response.getMessage());
}

/**
* Test updating response fields
*/
@Test
public void updateFields() {
RepositoryHookResponse response = new RepositoryHookResponse();
assertEquals("error", response.setMessage("error").getMessage());
assertEquals(404, response.setCode(404).getCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Collections;
import java.util.Date;
import java.util.Map;

import org.eclipse.egit.github.core.RepositoryHook;
import org.eclipse.egit.github.core.RepositoryHookResponse;
import org.junit.Test;

/**
* Unit test of {@link RepositoryHook}
*/
public class RepositoryHookTest {

/**
* Test default state of hook
*/
@Test
public void defaultState() {
RepositoryHook hook = new RepositoryHook();
assertFalse(hook.isActive());
assertNull(hook.getConfig());
assertNull(hook.getCreatedAt());
assertEquals(0, hook.getId());
assertNull(hook.getLastResponse());
assertNull(hook.getName());
assertNull(hook.getUpdatedAt());
assertNull(hook.getUrl());
}

/**
* Test updating hook fields
*/
@Test
public void updateFields() {
RepositoryHook hook = new RepositoryHook();
assertTrue(hook.setActive(true).isActive());
Map<String, String> config = Collections.singletonMap("a", "b");
assertEquals(config, hook.setConfig(config).getConfig());
assertEquals(new Date(1234), hook.setCreatedAt(new Date(1234))
.getCreatedAt());
assertEquals(150, hook.setId(150).getId());
RepositoryHookResponse response = new RepositoryHookResponse();
assertEquals(response, hook.setLastResponse(response).getLastResponse());
assertEquals("cihook", hook.setName("cihook").getName());
assertEquals(new Date(4455), hook.setUpdatedAt(new Date(4455))
.getUpdatedAt());
assertEquals("url", hook.setUrl("url").getUrl());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.egit.github.core.RepositoryId;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryId}
*/
public class RepositoryIdTest {

/**
* Create with null id string
*/
@Test
public void createFromNullString() {
assertNull(RepositoryId.createFromId(null));
}

/**
* Create with empty id string
*/
@Test
public void createFromEmptyString() {
assertNull(RepositoryId.createFromId(""));
}

/**
* Create from valid id string
*/
@Test
public void createFromString() {
RepositoryId id = RepositoryId.createFromId("a/b");
assertNotNull(id);
assertEquals("a", id.getOwner());
assertEquals("b", id.getName());
}

/**
* Create from null URL
*/
@Test
public void createFromNullUrl() {
assertNull(RepositoryId.createFromUrl((URL) null));
}

/**
* Create from null URL
*/
@Test
public void createFromNullStringUrl() {
assertNull(RepositoryId.createFromUrl((String) null));
}

/**
* Create from malformed string URL
*
* @throws MalformedURLException
*/
@Test
public void createFromMalformedStringUrl() throws MalformedURLException {
assertNull(RepositoryId.createFromUrl("http://:http//"));
}

/**
* From from invalid URL
*
* @throws MalformedURLException
*/
@Test
public void createFromInvalidUrl1() throws MalformedURLException {
assertNull(RepositoryId.createFromUrl(new URL("http://github.com")));
}

/**
* From from invalid URL
*
* @throws MalformedURLException
*/
@Test
public void createFromInvalidUrl2() throws MalformedURLException {
assertNull(RepositoryId.createFromUrl(new URL("http://github.com/")));
}

/**
* From from invalid URL
*
* @throws MalformedURLException
*/
@Test
public void createFromInvalidUrl3() throws MalformedURLException {
assertNull(RepositoryId.createFromUrl(new URL("http://github.com/a")));
}

/**
* From from invalid URL
*
* @throws MalformedURLException
*/
@Test
public void createFromInvalidUrl4() throws MalformedURLException {
assertNull(RepositoryId.createFromUrl(new URL("http://github.com/a/")));
}

/**
* From from valid URL
*
* @throws MalformedURLException
*/
@Test
public void createFromStringUrl() throws MalformedURLException {
RepositoryId id = RepositoryId
.createFromUrl("http://github.com/user/project");
assertNotNull(id);
assertEquals("user", id.getOwner());
assertEquals("project", id.getName());
}

/**
* From from valid URL
*
* @throws MalformedURLException
*/
@Test
public void createFromUrl() throws MalformedURLException {
RepositoryId id = RepositoryId.createFromUrl(new URL(
"http://github.com/user/project"));
assertNotNull(id);
assertEquals("user", id.getOwner());
assertEquals("project", id.getName());
}

/**
* Create with null owner
*/
@Test(expected = IllegalArgumentException.class)
public void createNullOwner() {
RepositoryId.create(null, "my proj");
}

/**
* Create with empty owner
*/
@Test(expected = IllegalArgumentException.class)
public void createEmptyOwner() {
RepositoryId.create("", "myproj");
}

/**
* Create with null name
*/
@Test(expected = IllegalArgumentException.class)
public void createNullName() {
RepositoryId.create("user", null);
}

/**
* Create with empty name
*/
@Test(expected = IllegalArgumentException.class)
public void createEmptyName() {
RepositoryId.create("user", "");
}

/**
* Create from static method
*/
@Test
public void create() {
RepositoryId id = RepositoryId.create("own", "project");
assertEquals("own", id.getOwner());
assertEquals("project", id.getName());
}

/**
* Verify repository id equality
*/
@Test
public void equality() {
RepositoryId id1 = new RepositoryId("auser", "bproject");
RepositoryId id2 = new RepositoryId("auser", "bproject");
RepositoryId id3 = new RepositoryId("auser", "bproject2");
assertTrue(id1.equals(id1));
assertTrue(id1.equals(id2));
assertFalse(id1.equals(id3));
assertFalse(id1.equals("content"));
assertEquals(id1.hashCode(), id2.hashCode());
assertEquals(id1.toString(), id2.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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.Repository;
import org.eclipse.egit.github.core.RepositoryIssue;
import org.junit.Test;

/**
* Unit tests of {@link RepositoryIssue}
*/
public class RepositoryIssueTest {

/**
* Test default state of issue
*/
@Test
public void defaultState() {
RepositoryIssue issue = new RepositoryIssue();
assertNull(issue.getRepository());
}

/**
* Test updating issue fields
*/
@Test
public void updateFields() {
RepositoryIssue issue = new RepositoryIssue();
Repository repo = new Repository();
assertEquals(repo, issue.setRepository(repo).getRepository());
}
}
Loading