This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Glenn Jayasuriya

Ranch Hand
+ Follow
since May 15, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Glenn Jayasuriya

My solution works.
Might not be the best solution, but gets the job done.
Set the range to 20 and filter for what i want.
I'm just going to try my solution.
I'll post how it goes here later.
I can always just convert to a diff solution later as well.
Hi there it's my first time using an API. I'm having a little trouble with the google calendar api. What i have is after a event gets printed out it gets the next event



The above is code to get the next event. But my problem is this:



The problem is when i run it, it says the next event is "example event". For me the next event should be "2nd event" because the start time of "example event" has already passed.

In the api there is a timeMax:


Timemax is the upper bounds of the start time. But what I really need is the lower bounds of the start time and the api doesn't have that.

Link to full list of parameters in the api: https://developers.google.com/google-apps/calendar/v3/reference/events/list

If my start time is [lower bounds, upper bounds] I want [the time now, upperbounds]

I guess a possible solution would be to get not just the "next event" but get like the "next 10 events". Then have a comparater to check if the event's start time (which i can get after i retrieve the events) is less than the current time.

If not get the "next event"

I'm just thinking worst case if all 10 events start before the start time and the 11th event starts after then the 11th event wouldn't get retrieved.

I'd have to use the list method with a query of 20 and repeat to get the "next 20 events" and perhaps have a counter on the last position (10).

I might also need to have an event in like 2050 or something so there will also be an event in the future.

Is that the best solution for this?
Hello,

I'm currently making a recipe book on android.
I'd like to be able to tag recipes however not sure what would be the best way to do this.

I was thinking of a table that will contain tag objects.
We could have positions 0 to 25 be the first letter of a tag, or just a hash function of a string.
Each position would have an arraylist of tags.
Each tag object would have a arraylist of recipes.

So to add a recipe just search if the tag is there, if not create the tag and add recipe to the tag object.
Search by first letter of the tag (or hash function) to get to the right column of the table, look for the tag and display all the recipes that have the tag.

Is there a better way to do this?
Any advice would be appreciated!
Thanks.
11 months ago

Jeanne Boyarsky wrote:Glenn,
It is a matter of style. I don't have any problems with a test having multiple assertions that cover the same scenario. Some people believe a test should only have one assertion.

I do have two observations:
1) It appears you are testing the value passed into the constructor is the value returned by getName(). If so, you could create a String variable so you aren't duplicating that String and to make the intent clearer.
2) Does the getName() method have logic in it? If it just returns the value (vs doing conversion/validation), most of your tests are overkill.



Ya it's a getter method.
I know now i shouldn't be testing that cause it's a waste of time.
I did have another question though, made  test for something that had logic:



I was reading somewhere that unit tests should be self contained.
Is it ok to declare private variables at the top like this.
Or within each method must I repeat instantiating the object in each one.
This way it's less repetitive but I worry that the object could possibly change between test methods and if it's wrong in one it could affect the other.
If that's the case i might just have to instantiate in each method.
11 months ago

Stephan van Hulst wrote:You can eliminate testName and returnedName. Just pass the name directly into the constructor, and pass the result of getName() directly to assertEquals(). Also, move each case to their own test method. One test should test one case. Rename your test methods to explain what they do: testNewRecipe(), testNewRecipeWithEmptyName(), testNewRecipeWithLongName(), testNewRecipeWithSpecialName().



My test code is in a class called RecipeTest so i don't think i need to write test for each method but I changed my code to this:



Question, these tests are for a method called getName.
Another method called getDirections could also use some of these test methods.
Am I allowed to add code in each test method that covers both the getName and getDireciton method at once?
So instead of called it "getNameSpecialCharacters" for instance I just call it "testSpecalCharacters" or something.
Or can each test method only correspond to one method of code?

Thanks!
11 months ago
First time doing unit tests, is this too repetitive? Thanks!


If it is too repetitive, what would you recommend to fix it?
Thanks!
11 months ago
I need help with the handling events issue.
Debugging is becoming more and more difficult for me.
Before it was easier but now there are times where I have no clue why something is not working.
1 year ago
Use the same loop to iterate over the array.
Use comparators like <,> etc
Keep track of the max and min value with a variable
1 year ago

Paul Clapham wrote:"Configuration" covers a lot of territory. Maybe there is supposed to be some other folder somewhere where your code expects to find files. Maybe you have to run the application as an administrator and you aren't. The list could go on indefinitely.

Don't take those guesses seriously, they are based on no evidence. You've got Eclipse running on the target machine? Good. Then run your application and see where exceptions are thrown, for a start. If that doesn't happen then you'll have to start debugging. But without any evidence of a problem you aren't going to be able to solve that problem.



And that's sorta my issue. I've already tried putting try and catch statements and as mentioned above have been running it through the debugger.
It would be easier if it would just tell me an error so I could know what to do in that case.
I might just have to rewrite this from scratch on the target computer.
Still wish I knew what the actual reason was.
1 year ago

Paul Clapham wrote:That means you haven't configured Eclipse to know where the source code is for the JRE it's using. Just click that debig button which gets you out of that method and back to whatever called it.

It doesn't have anything to do with why your code doesn't run on a different machine -- that would be because the other machine isn't configured the same way as the one you did your testing on.



Ok in eclipse i went to toolbar and went to Run --> Run Configurations.
I'm just comparing the configurations between the two machines.
The original machine had a runtime JRE of JavaSE-1.7 (Java SE 8 [1.8.0_40
The new machine has a runtime JRE of JavaSE-1.7 (java-8-openjdk-i386)
Besides that the jar files seem to be in the right places for their machines according to the sources section of the run configurations.

Am I looking at the wrong place?
Thanks.
1 year ago


Forgot the mention that when I step over this line it says that "this" was "source not found"
This referred to ScheduledThreadPoolExecutor so I guess it couldn't find ScheduledThreadPoolExecutor
Also mentioned this: java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@41aa62

This is what I see:
http://imgur.com/a/IvuLh
1 year ago
What I did was run eclipse on another machine. Made a new project with new java files and just copied the java code.
Imported all the jar files which removed all the error messages I was having. (Note also there were messages saying that the source level was wrong but if i just right clicked it resolved those problems for me).
I ran it in eclipse and same thing as with terminal, nothing happened.
So I ran it through the eclipse debugger with breakpoints and found my issues was with the following:


I took this code directly off the Google Spreadsheets API: https://developers.google.com/sheets/api/quickstart/java
I ran the debugger for eclipse on original machine and the eclipse debugger was able to get past this part just fine.
So I'm wondering if the spreadsheet code is what is causing my problem.
Which is a problem because I didn't write it, I don't understand how it works exactly.
From my understanding it uses OAuth consent, through a google wizard you can create a client json file, you add this to your java project to be credentials to the google app.
I made sure to add the json file to the resources folder of the new machine like I did with the old machine but no luck.
I even repeated the process of creating that json file as noted in the link above and included that new json file in the new machine but I had no luck with that as well.
1 year ago

Knute Snortum wrote:You probably should include .settings, .project, and .classpath in your .gitignore file as these files are very system specific and proprietary to Eclipse.  It also exposes the internal structure of your system to the public.



Ok thank you. Honestly I don't know very much about git and just used the github desktop app on my computer to sync with github.
1 year ago

Knute Snortum wrote:It looks to me that your project is very dependent on local jars and resources.  How did you build your runnable jar?  Have you considered using Maven or some other build program?



Hi I built my runnable jar through eclipse. Export ---> Generate runnable Jar ---> package required libraries into runnable Jar.
1 year ago