Posts

java - Unit testing with mockito for constructors -

i have 1 class. class first { private second second; public first(int num, string str) { second = new second(str); this.num = num; } ... // other methods } i want write unit tests public methods of class first. want avoid execution of constructor of class second. i did this: second second = mockito.mock(second.class); mockito.when(new second(any(string.class).thenreturn(null); first first = new first(null, null); it still calling constructor of class second. how can avoid it? once again problem unit-testing comes manually creating objects using new operator. consider passing created second instead: class first { private second second; public first(int num, second second) { this.second = second; this.num = num; } // other methods... } i know might mean major rewrite of api, there no other way. class doesn't have sense: mockito.when(new second(any(string.class).thenreturn(null))); first of mockito ...

javascript - play pls file in browser -

i need play pls file in website, each user can listen it. 1 way use flash , actionscript, i've been searching way play in browser using javascript or html5. is there way play pls files in browser using html5 or javascript? a pls file has format: [playlist] numberofentries=x file1=http://80.86.106.136:80/ file2=http://80.86.106.136:80/ ... so need read content , this var content = readpls(); var data = content.split('\n\r'); var number_of_files = data[1].replace('numberofentries=',''); var files = []; for(var i=0;i<number_of_files;i++){ files.push(data[2+i].replace("file"+(i+1),'')) } code needs work, way go (in js/as)

ruby on rails 3 - How to tell if reads are being redirect to MySQL slave on Rails3 -

[update] may use (or misuse) of seamless_database_pool gem. i setup master/slave setup on rails3 using seamless_database_pool . mean reads not being redirected slave? how can check @ mysql level? hoping show processlist this, i'm not seeing processes. [update] running show processlist on master displays queries being run, guess reads not being passed slave. the bin_log file has following (9's , x's added): /*!40019 set @@session.max_insert_delayed_threads=0*/; /*!50003 set @old_completion_type=@@completion_type,completion_type=0*/; delimiter /*!*/; \# @ 4 \#xxxxxxx 99:99:99 server id 2 end_log_pos 106 start: binlog v 4, server v 5.1.52-log created xxxx 99:99:99 @ startup rollback/*!*/; binlog ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx '/*!*/; \# @ 106 \#xxxx 99:99:99 server id 2 end_log_pos 125 stop delimiter ; \# end of log file rollback /* added mysqlbinlog */; /*!50003 set completion_type=@old_completion_type...

Ruby gem for text comparison -

i looking gem can compare 2 strings (in case paragraphs of text) , able gauge likelihood similar in content (with perhaps few words rearranged, changed). believe uses similar when users submit questions. i'd use diff::lcs: >> require "diff/lcs" >> seq1 = "lorem ipsum dolor sit amet consequtor".split(" ") >> seq2 = "lorem ipsum dolor amet sit consequtor".split(" ") 1.9.3-p194 :010 > diff::lcs.diff(seq1, seq2).length => 2 it uses longest common subsequence algorithm (the method using lcs diff described on the wiki page ).

Newbie Programming: HTML5 Display Image - button onclick= -

first time programmer here, writing simple program on html5. can't seem image display when button clicked. here code: <p> <center> <button onclick="deadtest()"> <img src="begintest.gif"/></button></center></p> <script language="javascript" type="text/javascript"> function deadtest() { <img style="border-width: 0px;" src="white.jpg" width="768" height="1280" /> } </script> have looked through countless sites , forums can't seem work. have tried alert() function , working. think must code call on image. first time programmer might idiotic. teach me, oh guru's... learn basics first on how call javascript function , how change properties. see sample demo. hope learn it. http://jsfiddle.net/ngrym/1/ <script type="text/javascript"> function...

c++ - Is it a good idea to shut down a class's thread member in the class's destructor? -

what's best way shut down boost thread managed c++ class when it's time object of class destroyed? have class creates , starts thread on construction , provides public wake() method wakes thread when it's time work. wake() method uses boost mutex , boost condition variable signal thread; thread procedure waits on condition variable, work , goes waiting. at moment, shut thread down in class's destructor, using boolean member variable "running" flag; clear flag , call notify_one() on condition variable. thread procedure wakes up, notices "running" false, , returns. here's code: class worker { public: worker(); ~worker(); void wake(); private: worker(worker const& rhs); // prevent copying worker& operator=(worker const& rhs); // prevent assignment void threadproc(); bool m_running; boost::mutex m_mutex; boost::condition_variable m_condition; boost::scoped_p...

httpclient - Tapestry, request processing from another application -

i'have 2 web appli, tapestry appli , simple web appli(servelt). in tapestry appli , have form, , when it'll sent, call httpclient sending informations author appli using apache's httpclient. void onsubmitfromform() { try { httpclient client = new defaulthttpclient(); httppost post = new httppost("http://localhost:8080/appli2/recep"); post.setheader("referer", "http://localhost:9090/app1/start"); list<namevaluepair> param = new arraylist<namevaluepair>(); param.add(new basicnamevaluepair("_data", getdata()); post.setentity(new urlencodedformentity(param)); httpresponse response = client.execute(post); response ????? } catch (exception e) { e.printstacktrace(); } } and in servelt recep of simple web appli(2) same below protected void dopost(httpservletrequest request, httpservletresponse re...