http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/cobertura_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/cobertura_spec.rb b/spec/java/cobertura_spec.rb index 662ae09..b5aafd9 100644 --- a/spec/java/cobertura_spec.rb +++ b/spec/java/cobertura_spec.rb @@ -55,7 +55,7 @@ describe Buildr::Cobertura do define('foo') { define('bar') } task('foo:bar:cobertura:instrument').invoke end - + it 'should not generate html if projects have no sources' do define('foo') { define('bar') } task('cobertura:html').invoke @@ -94,21 +94,21 @@ describe Buildr::Cobertura do import static junit.framework.Assert.assertTrue; import org.junit.Test; -public class FooTest { - +public class FooTest { + @Test - public void testReturnTrue() { + public void testReturnTrue() { assertTrue(Foo.returnTrue()); } } JAVA end - + it 'should not raise errors during execution' do define('foo') { cobertura.include 'Foo' } lambda {task("foo:cobertura:check").invoke}.should_not raise_error end - + end end end
http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/commands_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/commands_spec.rb b/spec/java/commands_spec.rb index 8f906c9..e9ac5e2 100644 --- a/spec/java/commands_spec.rb +++ b/spec/java/commands_spec.rb @@ -30,30 +30,30 @@ BUILD lambda { Java::Commands.java("org.apache.tools.ant.Main", :classpath => Buildr::Ant.dependencies) }.should_not show_info(/java/) lambda { Java::Commands.java("org.apache.tools.ant.Main", :classpath => Buildr::Ant.dependencies, :verbose => true) }.should show_info(/java/) end - + describe "Java::Commands.javac" do - + it "should compile java" do write "Foo.java", "public class Foo {}" lambda { Java::Commands.javac("Foo.java") }.should change {File.exist?("Foo.class")}.to(true) end - + it 'should let the user specify an output directory' do write "Foo.java", "public class Foo {}" lambda { Java::Commands.javac("Foo.java", :output => "classes") }.should change {File.exist?("classes/Foo.class")}.to(true) end - + it "should let the user specify a different name" do write "Foo.java", "public class Foo {}" lambda { Java::Commands.javac("Foo.java", :name => "bar") }.should show_info("Compiling 1 source files in bar") end - + it "should let the user specify a source path" do write "ext/org/Bar.java", "package org; public class Bar {}" write "Foo.java", "import org.Bar;\n public class Foo {}" lambda { Java::Commands.javac("Foo.java", :sourcepath => File.expand_path("ext")) }.should change {File.exist?("Foo.class")}.to(true) end - + it "should let the user specify a classpath" do write "ext/org/Bar.java", "package org; public class Bar {}" Java::Commands.javac("ext/org/Bar.java", :output => "lib") @@ -61,18 +61,18 @@ BUILD lambda { Java::Commands.javac("Foo.java", :classpath => File.expand_path("lib")) }.should change {File.exist?("Foo.class")}.to(true) end end - + describe "Java::Commands.javadoc" do - + it "should fail if no output is defined" do lambda { Java::Commands.javadoc("Foo.java") }.should raise_error(/No output defined for javadoc/) end - + it "should create javadoc" do write "Foo.java", "public class Foo {}" lambda { Java::Commands.javadoc("Foo.java", :output => "doc") }.should change {File.exist?("doc/Foo.html")}.to(true) end - + it "should accept file tasks as arguments" do foo = file("Foo.java") do |file| file.enhance do @@ -81,7 +81,7 @@ BUILD end lambda { Java::Commands.javadoc(foo, :output => "doc") }.should change {File.exist?("doc/Foo.html")}.to(true) end - + it "should accept projects as arguments" do write "src/main/java/Foo.java", "public class Foo {}" write "src/main/java/bar/Foobar.java", "package bar; public class Foobar {}" http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/compiler_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/compiler_spec.rb b/spec/java/compiler_spec.rb index e8c68f9..e23022b 100644 --- a/spec/java/compiler_spec.rb +++ b/spec/java/compiler_spec.rb @@ -268,4 +268,3 @@ describe 'javac compiler options' do ENV.delete "DEBUG" end end - http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/doc_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/doc_spec.rb b/spec/java/doc_spec.rb index f8f0f66..b7b47e5 100644 --- a/spec/java/doc_spec.rb +++ b/spec/java/doc_spec.rb @@ -53,4 +53,3 @@ describe 'Javadoc' do end end - http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/ecj_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/ecj_spec.rb b/spec/java/ecj_spec.rb index c765f04..43e531e 100644 --- a/spec/java/ecj_spec.rb +++ b/spec/java/ecj_spec.rb @@ -43,7 +43,7 @@ describe Buildr::Compiler::Ecj do foo.compile.compiler.should == :ecj end - describe "should compile a Java project just in the same way javac does" do + describe "should compile a Java project just in the same way javac does" do javac_spec = File.read(File.join(File.dirname(__FILE__), "compiler_spec.rb")) javac_spec = javac_spec.match(Regexp.escape("require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))\n")).post_match javac_spec.gsub!("javac", "ecj") @@ -103,5 +103,3 @@ describe Buildr::Compiler::Ecj do end end end - - http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/external_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/external_spec.rb b/spec/java/external_spec.rb index 539045e..1af49ea 100644 --- a/spec/java/external_spec.rb +++ b/spec/java/external_spec.rb @@ -53,5 +53,3 @@ describe Buildr::Compiler::ExternalJavac do end end - - http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/java_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/java_spec.rb b/spec/java/java_spec.rb index 3756e49..110b79e 100644 --- a/spec/java/java_spec.rb +++ b/spec/java/java_spec.rb @@ -63,7 +63,7 @@ describe 'Java.tools_jar' do write 'jdk/lib/tools.jar' ENV['JAVA_HOME'] = File.expand_path('jdk') end - + it 'should return the path to tools.jar' do Java.tools_jar.should point_to_path('jdk/lib/tools.jar') end @@ -75,7 +75,7 @@ describe 'Java.tools_jar' do write 'jdk/lib/tools.jar' ENV['JAVA_HOME'] = File.expand_path('jdk/jre') end - + it 'should return the path to tools.jar' do Java.tools_jar.should point_to_path('jdk/lib/tools.jar') end @@ -86,7 +86,7 @@ describe 'Java.tools_jar' do Java.instance_eval { @tools_jar = nil } ENV['JAVA_HOME'] = File.expand_path('jdk') end - + it 'should return nil' do Java.tools_jar.should be_nil end http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/java/run_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/run_spec.rb b/spec/java/run_spec.rb index 9c0a238..ea6ebf1 100644 --- a/spec/java/run_spec.rb +++ b/spec/java/run_spec.rb @@ -75,4 +75,3 @@ describe Run::JavaRunner do end end - http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/spec/xpath_matchers.rb ---------------------------------------------------------------------- diff --git a/spec/xpath_matchers.rb b/spec/xpath_matchers.rb index 33df7aa..a9120ff 100644 --- a/spec/xpath_matchers.rb +++ b/spec/xpath_matchers.rb @@ -1,121 +1,121 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with this -# work for additional information regarding copyright ownership. The ASF -# licenses this file to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -require 'rexml/document' -require 'rexml/element' - -module RSpec - module Matchers - - # check if the xpath exists one or more times - class HaveXpath - def initialize(xpath) - @xpath = xpath - end - - def matches?(response) - @response = response - doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response) - match = REXML::XPath.match(doc, @xpath) - not match.empty? - end - - def failure_message - "Did not find expected xpath #{@xpath}" - end - - def negative_failure_message - "Did find unexpected xpath #{@xpath}" - end - - def description - "match the xpath expression #{@xpath}" - end - end - - def have_xpath(xpath) - HaveXpath.new(xpath) - end - - # check if the xpath has the specified value - # value is a string and there must be a single result to match its - # equality against - class MatchXpath - def initialize(xpath, val) - @xpath = xpath - @val= val - end - - def matches?(response) - @response = response - doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response) - ok = true - REXML::XPath.each(doc, @xpath) do |e| - @actual_val = case e - when REXML::Attribute - e.to_s - when REXML::Element - e.text - else - e.to_s - end - return false unless @val == @actual_val - end - return ok - end - - def failure_message - "The xpath #{@xpath} did not have the value '#{@val}' It was '#{@actual_val}'" - end - - def description - "match the xpath expression #{@xpath} with #{@val}" - end - end - - def match_xpath(xpath, val) - MatchXpath.new(xpath, val) - end - - # checks if the given xpath occurs num times - class HaveNodes #:nodoc: - def initialize(xpath, num) - @xpath= xpath - @num = num - end - - def matches?(response) - @response = response - doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response) - match = REXML::XPath.match(doc, @xpath) - @num_found= match.size - @num_found == @num - end - - def failure_message - "Did not find expected number of nodes #{@num} in xpath #{@xpath} Found #{@num_found}" - end - - def description - "match the number of nodes #{@num}" - end - end - - def have_nodes(xpath, num) - HaveNodes.new(xpath, num) - end - - end +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with this +# work for additional information regarding copyright ownership. The ASF +# licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +require 'rexml/document' +require 'rexml/element' + +module RSpec + module Matchers + + # check if the xpath exists one or more times + class HaveXpath + def initialize(xpath) + @xpath = xpath + end + + def matches?(response) + @response = response + doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response) + match = REXML::XPath.match(doc, @xpath) + not match.empty? + end + + def failure_message + "Did not find expected xpath #{@xpath}" + end + + def negative_failure_message + "Did find unexpected xpath #{@xpath}" + end + + def description + "match the xpath expression #{@xpath}" + end + end + + def have_xpath(xpath) + HaveXpath.new(xpath) + end + + # check if the xpath has the specified value + # value is a string and there must be a single result to match its + # equality against + class MatchXpath + def initialize(xpath, val) + @xpath = xpath + @val= val + end + + def matches?(response) + @response = response + doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response) + ok = true + REXML::XPath.each(doc, @xpath) do |e| + @actual_val = case e + when REXML::Attribute + e.to_s + when REXML::Element + e.text + else + e.to_s + end + return false unless @val == @actual_val + end + return ok + end + + def failure_message + "The xpath #{@xpath} did not have the value '#{@val}' It was '#{@actual_val}'" + end + + def description + "match the xpath expression #{@xpath} with #{@val}" + end + end + + def match_xpath(xpath, val) + MatchXpath.new(xpath, val) + end + + # checks if the given xpath occurs num times + class HaveNodes #:nodoc: + def initialize(xpath, num) + @xpath= xpath + @num = num + end + + def matches?(response) + @response = response + doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response) + match = REXML::XPath.match(doc, @xpath) + @num_found= match.size + @num_found == @num + end + + def failure_message + "Did not find expected number of nodes #{@num} in xpath #{@xpath} Found #{@num_found}" + end + + def description + "match the number of nodes #{@num}" + end + end + + def have_nodes(xpath, num) + HaveNodes.new(xpath, num) + end + + end end http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/JavaSystemProperty/src/test/java/FooTest.java ---------------------------------------------------------------------- diff --git a/tests/JavaSystemProperty/src/test/java/FooTest.java b/tests/JavaSystemProperty/src/test/java/FooTest.java index 6901f83..11c0ee5 100644 --- a/tests/JavaSystemProperty/src/test/java/FooTest.java +++ b/tests/JavaSystemProperty/src/test/java/FooTest.java @@ -18,7 +18,7 @@ import org.junit.Test; public class FooTest { - + @Test public void testSomething() {} } http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/compile_with_parent/child/src/main/java/Foo.java ---------------------------------------------------------------------- diff --git a/tests/compile_with_parent/child/src/main/java/Foo.java b/tests/compile_with_parent/child/src/main/java/Foo.java index 77ce16c..b43747e 100644 --- a/tests/compile_with_parent/child/src/main/java/Foo.java +++ b/tests/compile_with_parent/child/src/main/java/Foo.java @@ -18,6 +18,6 @@ import org.apache.log4j.Logger; public class Foo { - + private static final Logger _logger = Logger.getLogger(Foo.class); } http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/helloWorld/src/main/java/HelloWorld.java ---------------------------------------------------------------------- diff --git a/tests/helloWorld/src/main/java/HelloWorld.java b/tests/helloWorld/src/main/java/HelloWorld.java index 8f5a867..eb25a00 100644 --- a/tests/helloWorld/src/main/java/HelloWorld.java +++ b/tests/helloWorld/src/main/java/HelloWorld.java @@ -16,7 +16,7 @@ */ public class HelloWorld { - + public void foo() { System.err.println("bar"); } http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/include_as/doc/index.html ---------------------------------------------------------------------- diff --git a/tests/include_as/doc/index.html b/tests/include_as/doc/index.html index f8a3e0b..51253d8 100644 --- a/tests/include_as/doc/index.html +++ b/tests/include_as/doc/index.html @@ -5,4 +5,4 @@ <body> Hello world </body> -</html> \ No newline at end of file +</html> http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/include_path/doc/index.html ---------------------------------------------------------------------- diff --git a/tests/include_path/doc/index.html b/tests/include_path/doc/index.html index f8a3e0b..51253d8 100644 --- a/tests/include_path/doc/index.html +++ b/tests/include_path/doc/index.html @@ -5,4 +5,4 @@ <body> Hello world </body> -</html> \ No newline at end of file +</html> http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/integration_testing.rb ---------------------------------------------------------------------- diff --git a/tests/integration_testing.rb b/tests/integration_testing.rb index 79ed051..7949bc0 100644 --- a/tests/integration_testing.rb +++ b/tests/integration_testing.rb @@ -21,9 +21,9 @@ require 'zip/zip' module Buildr module IntegrationTests - + def self.test(folder, cmd, after_block = nil) - + eval <<-TEST class #{folder.sub("-", "").capitalize} < Test::Unit::TestCase @@ -38,22 +38,22 @@ module Buildr end - end + end TEST end #BUILDR-320 still not resolved. #test "BUILDR-320", "--trace -P" - + test "JavaSystemProperty", "test" - + test "helloWorld", "package" - + test "compile_with_parent", "compile" - + test "junit3", "test" - + test "include_path", "package", <<-CHECK path = File.expand_path("#{TEST_DIR}/include_path/target/proj-1.0.zip") assert(File.exist?(path), "File exists?") @@ -62,7 +62,7 @@ assert(!zip.get_entry("distrib/doc/index.html").nil?) assert(!zip.get_entry("distrib/lib/slf4j-api-1.6.1.jar").nil?) } CHECK - + test "include_as", "package", <<-CHECK path = File.expand_path("#{TEST_DIR}/include_as/target/proj-1.0.zip") assert(File.exist? path) @@ -71,7 +71,7 @@ assert(!zip.get_entry("docu/index.html").nil?) assert(!zip.get_entry("lib/logging.jar").nil?) } CHECK - + test "package_war_as_jar", "package", <<-CHECK assert(File.exist? "#{TEST_DIR}/package_war_as_jar/target/webapp-1.0.jar") %x[cd #{TEST_DIR}/package_war_as_jar ; #{BUILDR} clean] http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/junit3/src/main/java/Foo.java ---------------------------------------------------------------------- diff --git a/tests/junit3/src/main/java/Foo.java b/tests/junit3/src/main/java/Foo.java index 5ff35f8..dea7f9d 100644 --- a/tests/junit3/src/main/java/Foo.java +++ b/tests/junit3/src/main/java/Foo.java @@ -16,7 +16,7 @@ */ public class Foo { - + public String bar() { return "bar"; } http://git-wip-us.apache.org/repos/asf/buildr/blob/37fec874/tests/junit3/src/test/java/FooTest.java ---------------------------------------------------------------------- diff --git a/tests/junit3/src/test/java/FooTest.java b/tests/junit3/src/test/java/FooTest.java index bfed84e..cd30a7c 100644 --- a/tests/junit3/src/test/java/FooTest.java +++ b/tests/junit3/src/test/java/FooTest.java @@ -19,10 +19,10 @@ import junit.framework.TestCase; import static junit.framework.Assert.assertEquals; public class FooTest extends TestCase { - + public void testFoo() { Foo foo = new Foo(); assertEquals("bar", foo.bar()); } - + }
