• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Writing content to TemporaryFolder and deleting file after the test  RSS feed

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im trying to write some strings to File created by TemporaryFolder. I need to provide 3 Strings:

Line1 a
Line2 b c
Line 3

1) I make this, but it does not add anything. Length of testedContent is still 0. I tried to flush FileWriter but nothing happened. What am I making wrong?



Stacktrace:



2) Should I do it in setup with @Before method or do it inside test?

3) I read that this folder will be deleted automatically, so I dont need to perform .deleteOnExit() on textFile?
 
Sheriff
Posts: 13454
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried this:
 
Junilu Lacar
Sheriff
Posts: 13454
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the same token, I would have expected you to be able to do this:

I would have expected the getContentFile() method to be overloaded so that it can take a String path argument as well as a File file argument.

Also, that method name is somewhat misleading. If it's getting the content of the file specified by the argument, a better name for that method would be just getContent(). That way, the code wouldn't be so repetitive and stutter-y.
 
must Janik
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Have you tried this:



Ye, I have tried.
My method looks like this:


and I have java.lang.AssertionError: array lengths differed, expected.length=3 actual.length=1.

Is it necessary to overload the getContent method? Because I will use method with textFile as a parameter only in this unit test. I will paste the method I want to unit-test, too:




 
must Janik
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Forgot about `\n`, that's why everything was in one line.
Then, could you tell me if I should call deleteOnExit() on File?
I read, that TemporaryFolder deletes everything alone.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!