add tests to ListPackagesCommand
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 14 Jul 2011 10:04:48 +0000 (14:04 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 14 Jul 2011 10:04:48 +0000 (14:04 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/exec/ListPackagesCommand.java
nuget-server/src/jetbrains/buildServer/nuget/server/exec/NuGetExecutor.java
nuget-server/src/jetbrains/buildServer/nuget/server/exec/NuGetExecutorImpl.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/server/ListPackagesCommandTest.java [new file with mode: 0644]
nuget-tests/src/testng-nuget-tests..xml

index 281eec374aba6e493d58032f2dc6614887a867ed..93b368a50c6e5d73d1864fec98a5ef2cf193b8c5 100644 (file)
@@ -38,6 +38,7 @@ public class ListPackagesCommand {
     myExec = exec;\r
   }\r
 \r
     myExec = exec;\r
   }\r
 \r
+  @NotNull\r
   public Collection<PackageInfo> checkForChanges(\r
           @NotNull final String source,\r
           @NotNull final String packageId,\r
   public Collection<PackageInfo> checkForChanges(\r
           @NotNull final String source,\r
           @NotNull final String packageId,\r
index 964fb40d5987f62054845e4162b3fad2dffd7969..3ee06b42ba4fc11431c00519b8a005a586f626df 100644 (file)
@@ -1,3 +1,19 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
 package jetbrains.buildServer.nuget.server.exec;\r
 \r
 import org.jetbrains.annotations.NotNull;\r
 package jetbrains.buildServer.nuget.server.exec;\r
 \r
 import org.jetbrains.annotations.NotNull;\r
@@ -9,6 +25,7 @@ import java.util.List;
  * Date: 14.07.11 13:23\r
  */\r
 public interface NuGetExecutor {\r
  * Date: 14.07.11 13:23\r
  */\r
 public interface NuGetExecutor {\r
+  @NotNull\r
   <T> T executeNuGet(@NotNull List<String> arguments,\r
                      @NotNull NuGetOutputProcessor<T> listener);\r
 }\r
   <T> T executeNuGet(@NotNull List<String> arguments,\r
                      @NotNull NuGetOutputProcessor<T> listener);\r
 }\r
index 4f1b6948db22d993668c8a912eae9326b4601f27..065bbbe991bfe5548ecbcf1846f363861240fc3f 100644 (file)
@@ -44,6 +44,7 @@ public class NuGetExecutorImpl implements NuGetExecutor {
     return new File(myPluginInfo.getPluginRoot(), "bin/JetBrains.TeamCity.NuGetRunner.exe");\r
   }\r
 \r
     return new File(myPluginInfo.getPluginRoot(), "bin/JetBrains.TeamCity.NuGetRunner.exe");\r
   }\r
 \r
+  @NotNull\r
   public <T> T executeNuGet(@NotNull final List<String> arguments,\r
                             @NotNull final NuGetOutputProcessor<T> listener) {\r
 \r
   public <T> T executeNuGet(@NotNull final List<String> arguments,\r
                             @NotNull final NuGetOutputProcessor<T> listener) {\r
 \r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/server/ListPackagesCommandTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/server/ListPackagesCommandTest.java
new file mode 100644 (file)
index 0000000..ac23b83
--- /dev/null
@@ -0,0 +1,87 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.tests.server;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.nuget.server.exec.*;\r
+import org.jmock.Expectations;\r
+import org.jmock.Mockery;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.util.*;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 14.07.11 13:27\r
+ */\r
+public class ListPackagesCommandTest extends BaseTestCase {\r
+  private Mockery m;\r
+  private NuGetExecutor exec;\r
+  private ListPackagesCommand cmd;\r
+\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    m = new Mockery();\r
+    exec = m.mock(NuGetExecutor.class);\r
+    cmd = new ListPackagesCommand(exec);\r
+  }\r
+\r
+  private void allowCommandLineCall(final String... cmd) {\r
+    final List<String> list = new ArrayList<String>(Arrays.<String>asList(cmd));\r
+    m.checking(new Expectations(){{\r
+      oneOf(exec).executeNuGet(with(equal(list)), with(any(ListPackagesCommandProcessor.class)));\r
+      will(returnValue(Collections.<PackageInfo>emptyList()));\r
+    }});\r
+  }\r
+\r
+  @Test\r
+  public void test_run_no_version() {\r
+    allowCommandLineCall(\r
+            "TeamCity.List",\r
+            "-Source",\r
+            "source",\r
+            "-Id",\r
+            "package"\r
+    );\r
+\r
+    Collection<PackageInfo> infos = cmd.checkForChanges("source", "package", null);\r
+\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_run_version() {\r
+    allowCommandLineCall(\r
+            "TeamCity.List",\r
+            "-Source",\r
+            "source",\r
+            "-Id",\r
+            "package",\r
+            "-Version",\r
+            "version"\r
+    );\r
+\r
+    Collection<PackageInfo> infos = cmd.checkForChanges("source", "package", "version");\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+}\r
index 47ae74cc595e4ddedf255370fc9b2e776bfb801c..b3f4b5f4f805eb765b1563bb63291aca1fb60cef 100644 (file)
@@ -9,6 +9,8 @@
 \r
       <class name="jetbrains.buildServer.nuget.tests.util.CompositeBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.util.DelegatingBuildProcessTest"/>\r
 \r
       <class name="jetbrains.buildServer.nuget.tests.util.CompositeBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.util.DelegatingBuildProcessTest"/>\r
+\r
+      <class name="jetbrains.buildServer.nuget.tests.server.ListPackagesCommandTest"/>\r
     </classes>\r
   </test>\r
 \r
     </classes>\r
   </test>\r
 \r