Michael Sampson

Ranch Hand
+ Follow
since Sep 24, 2008
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Sampson

So I shall skip all the history behind this question and do my best to diagnose the problem and as a group, maybe we all can come up with a solution. I am a bit surpised I am posting this. I would have thought I would have figured this out on my own. I am putting this question in beginning java because it is an install issue I believe. So trouble started when I tried to set up Eclipse Juno 4.2. I get the 'Could not open JAVA_HOME\lib\amd64\jvm.cfg' error. I search around and what is happening is I hava 64 bit operating system (Windows 7), I have the 64 bit eclipse application, and now I need the 64 bit JRE. I need the full JDK which comes with a JRE so I figure, this is a great opportunity to upgrade to Java 7, the 64 bit version. I now have gone out and downloaded it and installed it. I changed the JAVA_HOME variable to the new path. The PATH variable builds off JAVA_HOME. I also found out, when checking java from the command line on windows 7 on 64 bit, you need the 64 bit command window. Typing 'cmd' into the start menu was not working. So here is what my DOS window looks like right now. I copied and pasted into the form.

C:\Java\java7_64b\jre\bin>java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

C:\Java\java7_64b\jre\bin>cd ..

C:\Java\java7_64b\jre>java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode)

C:\Java\java7_64b\jre>set path

C:\Java\java7_64b\jre>set java_home


So this is fascinating. Clearly JAVA_HOME has the path to 64 bit Java 7 and when in the bin directory it indicates it is there however, when I pull up the DOS window I am defaulting to a different version of java I still have on the machine. To get a DOS window that even does anything, I have to launch from the 64 bit windows directory which is different from all the System32 directories. So I am wondering is it a Windows 7 secuirty/user problem? Am I still pointing to a 32 bit environment? Do I have something misspelled somewhere? Do I have to formally go and uninstall the previous version of java? I am thinking if I can get this machine, default pointing to Java 7 64bit, then I will be able to launch Eclipse 64 bit Juno 4.2 without the error message coming up.Thanks in advance for actually reading this post.

9 years ago
So first off thanks for all the contributions by everyone. I didn't expect this many responses on my question but I didn't understand that 'views' even existed. Now this makes complete sense that yes I was trying to remove something from a list while I was iterating over it and thus the concurrentModificationException. So everything Steve Luke said was accurate and this was a case where I didn't understand what the debugger was doing. Not using the debugger and just putting in a bunch of print statements with object.toString() provided a lot of helpful information. The r's going into every list are new references but all refer back to the same original objects. I captured the return of the unmodifieable list in a reference and print'd the 'toString()' and got '[]' not the Class@abc123 that I expected. So I thought refernces always pointed to an object or null. I did not know what 'views' were and that you can have references to them.
9 years ago
So this is something tricky I've seen and I know a work around but I neccesarily understand why it works. So here is my code that has been simplified quite a bit:

This will cause the notorious ConcurrentModificationException. I'm paraphrasing to simplify the definition but you cannot edit a list while you are iterating over it is what that exception means. Now the work around I've found is at the g.getRevDetails() (line 10) just make that the input parameter to the constructor of a new ArrayList holding type of RevDetail and tada, the exception goes away. What I don't get is, on the getter in group for the list, it is returning a list which I am thinking is actually a copy (a whole different instance of List) that of the list that Group holds a reference to. And with the debugger it looks like I'm looking a copy of the revDetail object(s) as well. Now, when the remove is called on group, and it is passing in this copy of the revDetail object, which looks like it is able to remove somthing (even though I believe it is a copy) and then the exception is thrown. Now when I do my fix to get around this exception, I still don't really get how it is different now. Without the fix, the getter returns an unmodifieable list but when the actual remove to the physcial list is called, it is an entirely different instance of a list in memory I believe. So I don't get why that works.
9 years ago
Maybe someone knows something about this but if not maybe just typing my question out could help resolve this either way here it goes...
So I am working with Oracle database that has a date field that will have date down to hours, minutes, seconds, not just year, month, day. Now for my domain object I have this:
class Group {

private java.util.Date startDate;

OK .... never mind I figured it out. So the deal is even though I have it as type Date in the domain object, in the criterial statment I cannot do this:

I have to do this:

It turns out that really a time stamp. Not a date. That was about a day's worth of work gone.
Pat, I'd like to solve the puzzle please....
So I figured this out on my own. I think the static inner class muddled my thought on this. Even if a class is static, whenNew can still be used. However if you're using a mock of a final class then PowerMock.createMock needs to be used. So here is how I did this:
add the final class to the list of prepareForTest at the class level:

then in the testmethod:

anyObject being a hamcrest matcher. createMock, replay, and explect all are static imports from the PowerMock class. Sorry for not posting the import statements.
10 years ago
I submitted this question on the powermock google message board as well but figured I do this here too. So I have a 3rd party library I have no source for but no it is a final class with an inner static class with a public method. I have a class I am trying to write a test for that uses it. I am posting this code example to see if anyone has any ideas. It is a big abreviation from the actaul code but I believe I get all the important parts. Sadly I did not save my previous question so I have retype this whole thing.

Here is a skeleton of the 3rd party library:

Here is the class that uses it:

and here's the test

So I am trying to figure out how to mock new of a static inner class of a final class so I can mock its method call.
10 years ago
So I solved my own problem on this. Something I think I failed to mention in the original post was that the class under test that had the DAO member had no setter for that member. Being that I did mentio it was annotated with @Inject, I think that might have been inferred but on with the solution. So the DAO mock in the test is annotated with @Mock and the class under test is a member of the test class and it is annotated @InjectMocks. Inside the setUP method, there is a call MockitoAnnotation.initMocks(this) and it initializes the DAO mock object and is in injected into the class under test. The @RunsWith is thus available to be set to PowerMockRunner.
10 years ago
So I spent some time searching on this and have some ideas on how to resolve my problem but thought I'd post this and see where it goes. So my problem is that I have a class I did not write but was trying to write the unit test for. It has private members which are DAO's. In the class under test the fields are annotated @Inject. Mocking those DAO's isn't hard. I was going to use the @Mock annotation and then @InjectMocks for the instance of the class under tetst. Now to do that, I know one way to do that is use the @RunWith(MockitoJunitRunner.class) and then another might be use the setUp method and do like a Spring Reflection util and call inject mocks or something. I am going to look into that further. A problem comes up that the method I am trying to test also has calls to a static method. Mocking static calls I am well familiar with but it also requires the @RunWith annotation but with PowerMockRunner class and of course I am pretty sure @RunWith can only take a single class. So I am trying to avoid updating the class under test, being that I didn't write it, but am not real sure how to resolve doing the injection of the mock objects and being able to mock out static method calls. Sorry if this was already asked but I thought I did a decent search through the forum.
10 years ago
I added the struts2-spring-plugin- to the classpath.
11 years ago
I got around this. I did 2 things to fix this and I don't know which did what. I went and download a spring to struts integration plugin. Then I made sure to identify the class in struts.xml to what the id name for the bean was in applicationContext.

From my research, the ContextLoaderPlugin was for Struts 1 being that it worked with the ActionServlet.
11 years ago
Dave or anyone else for that matter, I've done some more searching and I want to confirm that I've found the right path to go down to resolve this...
Looking at
to use the ContextLoaderPlugin
The article talks about doing one of 2 things (I have a choice)

A) Overriding the Struts RequestProcessor with Spring’s DelegatingRequestProcessor.
B) Delegate Struts Action management to the Spring framework.

In the struts.xml file, I declare a plugin and provide as a parameter the location of applicationContext

for overriding the struts request processer add

to struts.xml

or in the second way, I set the type in my struts action

which gives the spring container control over creating the object. The action will need to be declared in applicationContext.
Does this sound correct. I thought this would be easier than this. The examples of struts to spring I had seen previously did not include any of this.


11 years ago
I've done some searching and followed examples and I am trying to inject into a struts action a simple string using spring DI and I am unsuccessful.

I've got

defined for all requests for the struts filter
in web.xml

I've got

defined as a listener in web.xml

my struts in action is

has field aString with setter,

it is defined is struts.xml on the classpath

and in applicationContext I have the bean wired up:

I would have thought the property name should have been 'aString' but the deployer complained

inside the execute method of the action, aString is null. Nothing was injected. No run time errors at the console. The setter is there. Do I need to access the applicationContext and do a get by id name? I thought the spring container using the context xml would set the string for me when it created the action. I also found something talking about a struts plug-in for configuring spring but I suspect that was for earlier versions of spring and struts and is now deprecated or do I still need that?


11 years ago
A few weeks ago during a job interview that didn't go well, I got a xml question. This is as close as I remember it, "what two things make an xml designated as an xml document?" I know that's not exactly what he said but it something like that. I interrupted it as what are the rules of xml to make it a well formed xml document like if it were a jsp. I said all elements had to be closed properly and that scripting elements should not be allowed. Declaring a namespace and access members from it was the procedure to bring in a dynamic element. That was a few weeks ago but does anyone else know what he meant by that question?

So I did a quick search on this and didn't find the answer I was looking for. So I work for a company that uses velocity templates. That's fine and all but the way they have it set up is the template does not have an extension on the file, which typically would be .vm. So instead of myfile.vm we just have myfile. So there is a plugin for velocity editing which I have downloaded. I've been checking through the help facilities and there are great directions for making associations with extensions and certain editors but I could find where you define a default editor. I did figure out one way to get the velocity editor to come up and that was with using the open with option from the context menu. Just double clicking the file icon opens up a plain text editor with no syntax highlighting. I would like that plain text editor to be the velocity template editor.
Now I have other ways of doing this but I was trying not to clutter up code. I am looking for an elegant way to do this. I have a string "MON", which I would to become "Monday". Is there some already written static routine in java that can do this. I have looked at the Calendar class a bit but this is not what it is designed for. I am thinking I will just have to write my own class. Well there probably is a way to get it out of Calendar but it's probably some formatting trick. Any ideas?

12 years ago