Get path as String for file in source package structure

P

Petterson Mikael

Hi,

In a junit test:

public void testSendMsgWithAttachment(){
try {
SendMessage send = new SendMessage();
send.sendMsg(from, to, cc, bcc, subject, text, attachment);
fail("Test failed since no IOException was thrown");
} catch (Exception e) {
fail("Test failed du to unexpected exception" + e.toString());
}
}

The String 'attachment' is the path to attachment-file.

I have the file ( Attachment.txt) in my package structure (CVS):

net.sourceforge.app.message.test

How can I get a path as String that is possible to use in my tes ( so I
can retrieve the attachment).

cheers,

//mikael
 
O

Oliver Wong

Petterson Mikael said:
Hi,

In a junit test:

public void testSendMsgWithAttachment(){
try {
SendMessage send = new SendMessage();
send.sendMsg(from, to, cc, bcc, subject, text, attachment);
fail("Test failed since no IOException was thrown");
} catch (Exception e) {
fail("Test failed du to unexpected exception" + e.toString());
}
}

The String 'attachment' is the path to attachment-file.

I have the file ( Attachment.txt) in my package structure (CVS):

net.sourceforge.app.message.test

How can I get a path as String that is possible to use in my tes ( so I
can retrieve the attachment).

I think it depends a lot on the implementation of
SendMessage.sendMsg() and what it expects as the last parameter. E.g. does
it accept relative paths, or only absolute paths? Does it accept URLs?
etc.

- Oliver
 
D

Daniel Pitts

Hi,

In a junit test:

public void testSendMsgWithAttachment(){
try {
SendMessage send = new SendMessage();
send.sendMsg(from, to, cc, bcc, subject, text, attachment);
fail("Test failed since no IOException was thrown");
} catch (Exception e) {
fail("Test failed du to unexpected exception" + e.toString());
}

}

The String 'attachment' is the path to attachment-file.

I have the file ( Attachment.txt) in my package structure (CVS):

net.sourceforge.app.message.test

How can I get a path as String that is possible to use in my tes ( so I
can retrieve the attachment).

cheers,

//mikael

First, your test looks wrong.
public void testSendMsgWithAttachment(){
try {
SendMessage send = new SendMessage();
send.sendMsg(from, to, cc, bcc, subject, text, attachment);
fail("Test failed since no IOException was thrown");
} catch (IOException e) {
} catch (Exception e) {
fail("Test failed du to unexpected exception" + e.toString());
}
}

To get the URL of the attachment try:
URL attachmentUrl = getClass().getClassLoader().getResource("net/
sourceforge/app/message/test/Attachment.txt");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top