FileWrapperResourceTheoryTest fails if java.io.tmpdir is relative

Description

FileWrapperResourceTheoryTest fails if java.io.tmpdir is a relative path because the temporary directory root then also lacks a leading slash on Linux and the logic is incorrect, leading to a bad resource path.

Here are the failures seen without the patch, with -Djava.io.tmpdir=target. Notice the duplicated paths:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 Running org.geoserver.platform.resource.FileWrapperResourceTheoryTest Tests run: 33, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.074 sec <<< FAILURE! theoryAddingFileToDirectoryAddsResource(org.geoserver.platform.resource.FileWrapperResourceTheoryTest) Time elapsed: 3 sec <<< ERROR! org.junit.experimental.theories.internal.ParameterizedAssertionError: theoryAddingFileToDirectoryAddsResource(testPaths[2]) at org.junit.experimental.theories.Theories$TheoryAnchor.reportParameterizedError(Theories.java:192) at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:146) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithCompleteAssignment(Theories.java:127) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:111) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithIncompleteAssignment(Theories.java:120) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:109) at org.junit.experimental.theories.Theories$TheoryAnchor.evaluate(Theories.java:96) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: java.lang.AssertionError: Expected: is resource that is defined but: was <ResourceAdaptor(/home/ben/geoserver/src with spaces/geoserver/src/platform/target/junit5736649089550125717/home/ben/geoserver/src with spaces/geoserver/src/platform/target/junit5736649089550125717/DirC/newFileCreatedDirectly)> at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) at org.junit.Assert.assertThat(Assert.java:865) at org.junit.Assert.assertThat(Assert.java:832) at org.geoserver.platform.resource.ResourceTheoryTest.theoryAddingFileToDirectoryAddsResource(ResourceTheoryTest.java:420) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.experimental.theories.Theories$TheoryAnchor$2.evaluate(Theories.java:175) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:141) ... 26 more Running org.geoserver.platform.resource.PathsTest Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec Running org.geoserver.platform.resource.ResourcesTest Tests run: 34, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.065 sec <<< FAILURE! theoryAddingFileToDirectoryAddsResource(org.geoserver.platform.resource.ResourcesTest) Time elapsed: 2 sec <<< ERROR! org.junit.experimental.theories.internal.ParameterizedAssertionError: theoryAddingFileToDirectoryAddsResource(testPaths[2]) at org.junit.experimental.theories.Theories$TheoryAnchor.reportParameterizedError(Theories.java:192) at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:146) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithCompleteAssignment(Theories.java:127) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:111) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithIncompleteAssignment(Theories.java:120) at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:109) at org.junit.experimental.theories.Theories$TheoryAnchor.evaluate(Theories.java:96) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: java.lang.AssertionError: Expected: is resource that is defined but: was <ResourceAdaptor(/home/ben/geoserver/src with spaces/geoserver/src/platform/target/junit3049597659115012310/home/ben/geoserver/src with spaces/geoserver/src/platform/target/junit3049597659115012310/DirC/newFileCreatedDirectly)> at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) at org.junit.Assert.assertThat(Assert.java:865) at org.junit.Assert.assertThat(Assert.java:832) at org.geoserver.platform.resource.ResourceTheoryTest.theoryAddingFileToDirectoryAddsResource(ResourceTheoryTest.java:420) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.experimental.theories.Theories$TheoryAnchor$2.evaluate(Theories.java:175) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:141) ... 26 more

Environment

Linux

Status

Assignee

Ben Caradoc-Davies

Reporter

Ben Caradoc-Davies

Triage

None

Fix versions

Affects versions

2.13.1
2.12.3
2.14-RC

Components

Priority

Medium